{"record":{"id":"f245332f656a6d22","repo":"nsqio/nsq","slug":"err-error","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"bench/bench_reader/bench_reader.go","lineNumber":106,"sourceCode":"\t\tpanic(err.Error())\n\t}\n\t_, err = nsq.Subscribe(topic, channel).WriteTo(rw)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\trdyChan <- 1\n\t<-goChan\n\t_, err = nsq.Ready(*rdy).WriteTo(rw)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\terr = rw.Flush()\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\t_, err = nsq.ReadResponse(rw)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\t_, err = nsq.ReadResponse(rw)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tvar msgCount int64\n\tgo func() {\n\t\ttime.Sleep(td)\n\t\t_ = conn.Close()\n\t}()\n\tfor {\n\t\tresp, err := nsq.ReadResponse(rw)\n\t\tif err != nil {\n\t\t\tif errors.Is(err, net.ErrClosed) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tpanic(err.Error())\n\t\t}","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/nsqio/nsq/blob/85cf10c09c6c3c86160d6f0eb156f62d0efc1648/bench/bench_reader/bench_reader.go#L88-L124","documentation":"bench_reader panics when the initial nsq.Ready(*rdy).WriteTo(rw) fails while writing the RDY command into the buffered connection to nsqd. WriteTo only fails on connection-level problems (broken pipe, reset, closed conn) — at this point the TCP dial and protocol magic already succeeded. The panic (with err.Error() as the message) crashes the reader goroutine and the whole benchmark, since there is no recover.","triggerScenarios":"nsqd closes/resets the connection right after IDENTIFY (bad IDENTIFY payload, max clients reached); the RDY count is invalid (0 or negative, nsqd rejected an earlier command and closed); conn killed by a proxy/firewall; *rdy flag malformed so nsq.Ready produced a bad command.","commonSituations":"Running bench_reader against an nsqd that hit --max-rdy-count or connection limits; stale conn through LB idle timeout; benchmark started before nsqd finished booting; passing -rdy=0.","solutions":["Check nsqd logs for why it dropped the client (invalid command, RDY limit, too many clients).","Re-run with a sane -rdy (>=1, <= nsqd --max-rdy-count default 2500).","Ensure the target nsqd is up and reachable before launching bench_reader.","Drop proxies/LBs between bench and nsqd, or raise their idle timeouts."],"exampleFix":"# before\nbench_reader -rdy=0 ...  # invalid RDY, nsqd drops conn\n\n# after\nbench_reader -rdy=200 ...","handlingStrategy":"validation","validationCode":"rdy := flag.Int(\"rdy\", 200, \"rdy count\")\n// after flag.Parse():\nif *rdy < 1 || *rdy > 2500 {\n    log.Fatalf(\"rdy must be in [1, nsqd max-rdy-count (default 2500)]\")\n}","typeGuard":null,"tryCatchPattern":"// bench tools panic; wrap main to get a clean message instead of a stack:\ndefer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"bench_reader failed: %v\", r)\n    }\n}()","preventionTips":["Validate -rdy bounds before connecting.","Wait for nsqd readiness (e.g. TCP check on 4150) before starting the bench.","Check nsqd logs immediately after any bench panic — it usually states the rejection reason."],"tags":["bench","nsq-client","panic","tcp","rdy","go"],"backgroundTag":null,"analyzedSha":"85cf10c09c6c3c86160d6f0eb156f62d0efc1648","analyzedAt":"2026-08-16T00:53:05.009Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}