{"record":{"id":"2506f703090f0d83","repo":"probelabs/goreplay","slug":"handle-buffer-size-error-q-interface-q","errorCode":null,"errorMessage":"handle buffer size error: %q, interface: %q","messagePattern":"handle buffer size error: %q, interface: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/capture/capture.go","lineNumber":453,"sourceCode":"\t\tfor _, i := range infs {\n\t\t\tif i.Name == ifi.Name {\n\t\t\t\tsnap = i.MTU + 200\n\t\t\t}\n\t\t}\n\t}\n\n\tif snap == 0 {\n\t\tsnap = 64<<10 + 200\n\t}\n\n\terr = inactive.SetSnapLen(snap)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"snapshot length error: %q, interface: %q\", err, ifi.Name)\n\t}\n\tif l.config.BufferSize > 0 {\n\t\terr = inactive.SetBufferSize(int(l.config.BufferSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"handle buffer size error: %q, interface: %q\", err, ifi.Name)\n\t\t}\n\t}\n\tif l.config.BufferTimeout == 0 {\n\t\tl.config.BufferTimeout = 2000 * time.Millisecond\n\t}\n\terr = inactive.SetTimeout(l.config.BufferTimeout)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"handle buffer timeout error: %q, interface: %q\", err, ifi.Name)\n\t}\n\thandle, err = inactive.Activate()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"PCAP Activate device error: %q, interface: %q\", err, ifi.Name)\n\t}\n\n\tbpfFilter := l.config.BPFFilter\n\tif bpfFilter == \"\" {\n\t\tbpfFilter = l.Filter(ifi)\n\t}","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/probelabs/goreplay/blob/251e45abd242886bb64ff2b2dc98789556b56330/internal/capture/capture.go#L435-L471","documentation":"When config.BufferSize > 0, PcapHandle calls inactive.SetBufferSize to size the kernel ring buffer; failure is wrapped as \"handle buffer size error: <err>, interface: <name>\". It indicates libpcap/the kernel rejected the requested buffer size for this capture handle.","triggerScenarios":"Setting l.config.BufferSize to a value the platform cannot honor (e.g. larger than net.core.rmem_max allows after doubling, non-page-aligned, or overflowing int on 32-bit) so SetBufferSize fails.","commonSituations":"Very large buffer sizes on hosts without raised net.core.rmem_max/net.core.rmem_default sysctls; 32-bit builds where the size overflows; buffer sizes below the kernel minimum; copying af_packet MB-sized values to a pcap listener expecting different units.","solutions":["Raise kernel limits: sysctl -w net.core.rmem_max=<bytes> and net.core.rmem_default=<bytes>, then retry","Lower config.BufferSize to a value within kernel limits (e.g. 2-32 MB)","Verify units are bytes and the value fits in int on the target architecture","Only set BufferSize when you have a specific need; leave it 0 for defaults"],"exampleFix":"// before\ncfg.BufferSize = 1 << 30 // 1GB, rmem_max too small\n// after\n// sysctl -w net.core.rmem_max=268435456\ncfg.BufferSize = 32 << 20 // 32MB","handlingStrategy":"validation","validationCode":"max, err := sysctlRead(\"net/core/rmem_max\")\nif err == nil {\n    if v, _ := strconv.Atoi(max); cfg.BufferSize > int(v) {\n        return fmt.Errorf(\"BufferSize %d exceeds rmem_max %d\", cfg.BufferSize, v)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"handle buffer size error\") {\n    log.Warnf(\"buffer size rejected, retrying with 8MB: %v\", err)\n    cfg.BufferSize = 8 << 20\n    handle, err = l.PcapHandle(ifi)\n}","preventionTips":["Raise net.core.rmem_max/rmem_default when requesting large buffers","Keep BufferSize within a few MB to tens of MB unless tuned","Confirm units are bytes and values fit int on 32-bit builds"],"tags":["go","pcap","buffer-size","kernel"],"backgroundTag":"pcap-buffer-size-rejected","analyzedSha":"251e45abd242886bb64ff2b2dc98789556b56330","analyzedAt":"2026-09-02T16:44:11.369Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}