{"record":{"id":"4a38d14cf7baa296","repo":"prometheus/node_exporter","slug":"calloc-failed","errorCode":null,"errorMessage":"calloc() failed","messagePattern":"calloc\\(\\) failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"collector/devstat_dragonfly.go","lineNumber":135,"sourceCode":"\t\t\t\"The total number of transactions completed.\",\n\t\t\t[]string{\"device\"}, nil,\n\t\t),\n\t\tblocksDesc: prometheus.NewDesc(\n\t\t\tprometheus.BuildFQName(namespace, devstatSubsystem, \"blocks_total\"),\n\t\t\t\"The total number of bytes given in terms of the devices blocksize.\",\n\t\t\t[]string{\"device\"}, nil,\n\t\t),\n\t\tlogger: logger,\n\t}, nil\n}\n\nfunc (c *devstatCollector) Update(ch chan<- prometheus.Metric) error {\n\tcount := C._get_ndevs()\n\tif count == -1 {\n\t\treturn errors.New(\"getdevs() failed\")\n\t}\n\tif count == -2 {\n\t\treturn errors.New(\"calloc() failed\")\n\t}\n\n\tfor i := C.int(0); i < count; i++ {\n\t\tstats := C._get_stats(i)\n\t\tdevice := fmt.Sprintf(\"%s%d\", C.GoString(&stats.device[0]), stats.unit)\n\n\t\tch <- prometheus.MustNewConstMetric(c.bytesDesc, prometheus.CounterValue, float64(stats.bytes), device)\n\t\tch <- prometheus.MustNewConstMetric(c.transfersDesc, prometheus.CounterValue, float64(stats.transfers), device)\n\t\tch <- prometheus.MustNewConstMetric(c.blocksDesc, prometheus.CounterValue, float64(stats.blocks), device)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":117,"sourceCodeEnd":149,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/devstat_dragonfly.go#L117-L149","documentation":"In the DragonFly BSD devstat collector (devstat_dragonfly.go), C._get_ndevs() returns -2 when its internal calloc() of the device-stat array fails, i.e. the process could not allocate memory for device statistics. Update returns errors.New(\"calloc() failed\") and this scrape's disk metrics are dropped.","triggerScenarios":"C._get_ndevs() == -2 in devstatCollector.Update — the C helper's calloc(count, sizeof(...)) returned NULL, which happens when the requested allocation size exceeds available memory.","commonSituations":"Hosts under severe memory pressure or with very low rlimits (ulimit -v / jail memory caps); pathological device counts reported by devstat causing a huge allocation.","solutions":["Check host free memory and rlimits (ulimit -v, jail/cgroup memory caps) and raise them for node_exporter","Restart node_exporter if the process is leaking or fragmented","Investigate why devstat reports a very large device count; a corrupt devstat state can trigger oversized allocations","Disable the devstat collector if memory-constrained hosts cannot afford it"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := c.Update(ch); err != nil {\n    if strings.Contains(err.Error(), \"calloc() failed\") {\n        c.logger.Error(\"devstat allocation failed; check host memory/rlimits\", \"err\", err)\n    }\n    return err // non-retryable until memory frees up; alert on it\n}","preventionTips":["Raise rlimits (ulimit -v) and avoid hard memory caps for the exporter process","Alert on host memory pressure so calloc failures never occur silently","Investigate abnormally large device counts from devstat that inflate allocation size","Restart the exporter if allocation failures repeat"],"tags":["cgo","memory-allocation","devstat","dragonfly","bsd"],"backgroundTag":"memory-allocation-failed","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}