{"record":{"id":"d6926a4d49200c71","repo":"probelabs/goreplay","slug":"handle-buffer-timeout-error-q-interface-q","errorCode":null,"errorMessage":"handle buffer timeout error: %q, interface: %q","messagePattern":"handle buffer timeout error: %q, interface: %q","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/capture/capture.go","lineNumber":461,"sourceCode":"\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}\n\tfmt.Println(\"Interface:\", ifi.Name, \". BPF Filter:\", bpfFilter)\n\terr = handle.SetBPFFilter(bpfFilter)\n\tif err != nil {\n\t\thandle.Close()\n\t\treturn nil, fmt.Errorf(\"BPF filter error: %q%s, interface: %q\", err, bpfFilter, ifi.Name)\n\t}\n\treturn\n}","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/probelabs/goreplay/blob/251e45abd242886bb64ff2b2dc98789556b56330/internal/capture/capture.go#L443-L479","documentation":"After applying options, PcapHandle sets the read timeout via inactive.SetTimeout(config.BufferTimeout), defaulting it to 2000ms when zero. Failure is wrapped as \"handle buffer timeout error: <err>, interface: <name>\". It means libpcap rejected the timeout value on the inactive handle (e.g. negative duration).","triggerScenarios":"Calling PcapHandle with l.config.BufferTimeout negative (e.g. from a misparsed config like \"-5s\") or otherwise invalid so SetTimeout fails before Activate.","commonSituations":"YAML/JSON parsing quirks producing negative durations; manually computing milliseconds and passing a negative int; confusion between time.Duration units when constructing the config programmatically.","solutions":["Validate BufferTimeout is non-negative (and non-zero so the 2000ms default applies) before calling PcapHandle","Reset the config value to 0 to use the built-in 2000ms default","Fix duration parsing (use time.ParseDuration) so the value cannot be negative","Wrap the call and surface the wrapped %q error for the underlying libpcap cause"],"exampleFix":"// before\ncfg.BufferTimeout = -1 * time.Second // invalid\n// after\nif cfg.BufferTimeout < 0 { cfg.BufferTimeout = 0 } // -> default 2000ms","handlingStrategy":"validation","validationCode":"if cfg.BufferTimeout < 0 {\n    return fmt.Errorf(\"BufferTimeout must be >= 0, got %v\", cfg.BufferTimeout)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"handle buffer timeout error\") {\n    log.Warnf(\"timeout rejected, using default: %v\", err)\n    cfg.BufferTimeout = 0\n    handle, err = l.PcapHandle(ifi)\n}","preventionTips":["Never allow negative durations into config (validate after parsing)","Leave BufferTimeout at 0 to get the 2000ms default","Use time.ParseDuration to avoid unit confusion"],"tags":["go","pcap","timeout","libpcap"],"backgroundTag":"invalid-pcap-timeout","analyzedSha":"251e45abd242886bb64ff2b2dc98789556b56330","analyzedAt":"2026-09-02T16:44:11.369Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}