Skip to content

Commit

Permalink
producer: fix panic when conn is never assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Sep 3, 2014
1 parent ac4e04f commit 92b67b2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 92b67b2

Please sign in to comment.