nsqio/nsq · error

err.Error()

Error message

err.Error()

What it means

bench_writer panics when net.DialTimeout("tcp", tcpAddr, time.Second) fails while connecting a publisher worker to nsqd: dial error or no completion within 1s (timeout produces 'i/o timeout'). err.Error() is the panic message. All pubWorker goroutines crash the process on any single failed dial; no retry exists.

Source

Thrown at bench/bench_writer/bench_writer.go:77

	}

	start := time.Now()
	close(goChan)
	wg.Wait()
	end := time.Now()
	duration := end.Sub(start)
	tmc := atomic.LoadInt64(&totalMsgCount)
	log.Printf("duration: %s - %.03fmb/s - %.03fops/s - %.03fus/op",
		duration,
		float64(tmc*int64(*size))/duration.Seconds()/1024/1024,
		float64(tmc)/duration.Seconds(),
		float64(duration/time.Microsecond)/float64(tmc))
}

func pubWorker(td time.Duration, tcpAddr string, batchSize int, batch [][]byte, topic string, rdyChan chan int, goChan chan int) {
	conn, err := net.DialTimeout("tcp", tcpAddr, time.Second)
	if err != nil {
		panic(err.Error())
	}
	_, err = conn.Write(nsq.MagicV2)
	if err != nil {
		panic(err.Error())
	}
	rw := bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn))
	ci := make(map[string]interface{})
	ci["client_id"] = "writer"
	ci["hostname"] = "writer"
	ci["user_agent"] = fmt.Sprintf("bench_writer/%s", nsq.VERSION)
	cmd, _ := nsq.Identify(ci)
	_, err = cmd.WriteTo(rw)
	if err != nil {
		panic(err.Error())
	}
	rdyChan <- 1
	<-goChan
	err = rw.Flush()

View on GitHub (pinned to 85cf10c09c)

Solutions

  1. Verify nsqd is accepting: `nc -zv host 4150`, then start bench_writer.
  2. Pass the correct flag: bench_writer --nsqd-tcp-address=127.0.0.1:4150.
  3. If latency is real, patch DialTimeout's budget in bench_writer/bench_writer.go:77 to e.g. 5*time.Second (it is a benchmark tool; local edits are fine).
  4. Reduce -c workers or stagger startup so the accept queue does not overflow.

Example fix

// before
conn, err := net.DialTimeout("tcp", tcpAddr, time.Second)
if err != nil {
	panic(err.Error())
}

// after
conn, err := net.DialTimeout("tcp", tcpAddr, 5*time.Second)
if err != nil {
	log.Fatalf("dial %s: %v", tcpAddr, err)
}
Defensive patterns

Strategy: validation

Validate before calling

conn, err := net.DialTimeout("tcp", addr, time.Second)
if err != nil { log.Fatalf("nsqd unreachable at %s: %v", addr, err) }
conn.Close()
// only then start bench_writer

Try / catch

defer func() {
    if r := recover(); r != nil {
        log.Fatalf("bench_writer dial failed: %v", r)
    }
}()

Prevention

When it happens

Trigger: nsqd not started/listening yet; wrong --nsqd-tcp-address; 1-second dial budget exceeded on slow networks, DNS delays, or under connection storms with many parallel workers; firewall dropping SYN (timeout rather than refused).

Common situations: Launching bench_writer in a script before nsqd is ready (race); remote/high-latancy nsqd where 1s is tight; huge -c (workers) counts causing accept-queue saturation during dial; container networks with slow DNS for hostnames.

Related errors


AI-assisted analysis of nsqio/nsq@85cf10c09c (2026-08-16). Data as JSON: /api/errors/88e2b4fcf36aa088. Report an issue: GitHub.