Lock the connection when setting it on the protobuf client.
parent
e8d2352c9c
commit
2b6dd3778f
|
@ -186,16 +186,20 @@ func (self *ProtobufClient) reconnect() {
|
||||||
if !swapped {
|
if !swapped {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
self.connectionStatus = IS_CONNECTED
|
||||||
|
}()
|
||||||
|
|
||||||
self.Close()
|
self.Close()
|
||||||
conn, err := net.DialTimeout("tcp", self.hostAndPort, self.writeTimeout)
|
conn, err := net.DialTimeout("tcp", self.hostAndPort, self.writeTimeout)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
self.connLock.Lock()
|
||||||
|
defer self.connLock.Unlock()
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
log.Info("connected to %s", self.hostAndPort)
|
log.Info("connected to %s", self.hostAndPort)
|
||||||
} else {
|
} else {
|
||||||
log.Error("failed to connect to %s", self.hostAndPort)
|
log.Error("failed to connect to %s", self.hostAndPort)
|
||||||
}
|
}
|
||||||
self.connectionStatus = IS_CONNECTED
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue