From b412017858ce6c5f72d6e288d7caea02e3ff8193 Mon Sep 17 00:00:00 2001 From: Matt Reiferson Date: Tue, 2 Sep 2014 20:16:11 -0400 Subject: [PATCH] producer: fix panic when conn is never assigned --- producer.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/producer.go b/producer.go index d6224ee0..be0755df 100644 --- a/producer.go +++ b/producer.go @@ -214,17 +214,15 @@ func (w *Producer) connect() error { w.log(LogLevelInfo, "(%s) connecting to nsqd", w.addr) - conn := NewConn(w.addr, &w.config, &producerConnDelegate{w}) - conn.SetLogger(w.logger, w.logLvl, fmt.Sprintf("%3d (%%s)", w.id)) - - _, err := conn.Connect() + w.conn = NewConn(w.addr, &w.config, &producerConnDelegate{w}) + w.conn.SetLogger(w.logger, w.logLvl, fmt.Sprintf("%3d (%%s)", w.id)) + _, err := w.conn.Connect() if err != nil { - conn.Close() + w.conn.Close() w.log(LogLevelError, "(%s) error connecting to nsqd - %s", w.addr, err) atomic.StoreInt32(&w.state, StateInit) return err } - w.conn = conn w.wg.Add(1) go w.router()