{"record":{"id":"e7d04d5038a9fab0","repo":"prometheus/node_exporter","slug":"invalid-tcp-states-data-expected-d-entries-foun","errorCode":null,"errorMessage":"invalid TCP states data: expected %d entries, found %d","messagePattern":"invalid TCP states data: expected (.+?) entries, found (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netstat_freebsd.go","lineNumber":265,"sourceCode":"\t}\n\n\tif len(data) < expectedSize {\n\t\treturn nil, errors.New(\"Data Size mismatch\")\n\t}\n\treturn data, nil\n}\n\nfunc getTCPStates() ([]uint64, error) {\n\n\t// This sysctl returns an array of uint64\n\tdata, err := sysctlRaw(\"net.inet.tcp.states\")\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(data)/8 != len(tcpStates) {\n\t\treturn nil, fmt.Errorf(\"invalid TCP states data: expected %d entries, found %d\", len(tcpStates), len(data)/8)\n\t}\n\n\tstates := make([]uint64, 0)\n\n\toffset := 0\n\tfor range len(tcpStates) {\n\t\ts := data[offset : offset+8]\n\t\toffset += 8\n\t\tstates = append(states, binary.NativeEndian.Uint64(s))\n\t}\n\treturn states, nil\n}\n\ntype netStatCollector struct {\n\tnetStatMetric *prometheus.Desc\n}\n\nfunc init() {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netstat_freebsd.go#L247-L283","documentation":"The FreeBSD netstat collector reads the kernel TCP state table via sysctl and expects the returned binary buffer to contain exactly one 8-byte entry per known TCP state. If the buffer size divided by 8 does not match the length of the tcpStates name table, the collector cannot safely map entries to state names and returns this error instead of emitting wrong metrics.","triggerScenarios":"The sysctl call returns a buffer whose length/8 differs from len(tcpStates); this happens when the kernel returns fewer or more TCP state counters than the collector's hardcoded state list (e.g. a newer/older FreeBSD kernel with a changed number of TCP states, or a truncated/partial sysctl read).","commonSituations":"Running node_exporter built for one FreeBSD version on a kernel with a different TCPstate count; unusual kernels or ABI drift between userland sysctl expectations and the running kernel.","solutions":["Rebuild/run the node_exporter version that matches your FreeBSD kernel version so the tcpStates table matches the kernel's output.","Verify the sysctl value backing this data (e.g. net.inet.tcp.states / kern IPC data) returns the expected entry count on the host.","If a kernel version changed the state list, update the tcpStates table in collector/netstat_freebsd.go to match and file/track an upstream issue.","Report the kernel version and the 'found' value from the error message upstream to help extend the compatibility table."],"exampleFix":"// before (collector assumes fixed state count)\nif len(data)/8 != len(tcpStates) {\n\treturn nil, fmt.Errorf(\"invalid TCP states data: expected %d entries, found %d\", len(tcpStates), len(data)/8)\n}\n// after (optionally tolerate extra kernel entries by parsing only the known prefix)\nif len(data)/8 < len(tcpStates) {\n\treturn nil, fmt.Errorf(\"invalid TCP states data: expected at least %d entries, found %d\", len(tcpStates), len(data)/8)\n}","handlingStrategy":"validation","validationCode":"// Before parsing, check that the sysctl buffer size matches the state table\n// (this is what the collector does; if you extend it, keep the check):\n// data, _ := sysctlRaw(...)\n// if len(data)/8 != len(tcpStates) { /* skip TCP state metrics this scrape */ }","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Pin node_exporter versions to the FreeBSD release they were built/tested against.","After kernel upgrades, redeploy a node_exporter build matching the new kernel.","Monitor scrape errors so a mismatch is noticed immediately.","When porting to new FreeBSD versions, update the tcpStates table and its tests first."],"tags":["freebsd","netstat","tcp","sysctl","data-length-mismatch"],"backgroundTag":"schema-validation-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"}