Lock the connection when setting it on the protobuf client.

pull/269/head
Paul Dix 2014-02-24 13:55:43 -05:00
parent e8d2352c9c
commit 2b6dd3778f
1 changed files with 5 additions and 1 deletions

View File

@ -186,16 +186,20 @@ func (self *ProtobufClient) reconnect() {
if !swapped {
return
}
defer func() {
self.connectionStatus = IS_CONNECTED
}()
self.Close()
conn, err := net.DialTimeout("tcp", self.hostAndPort, self.writeTimeout)
if err == nil {
self.connLock.Lock()
defer self.connLock.Unlock()
self.conn = conn
log.Info("connected to %s", self.hostAndPort)
} else {
log.Error("failed to connect to %s", self.hostAndPort)
}
self.connectionStatus = IS_CONNECTED
return
}