mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-30 08:06:40 +02:00
Merge pull request #742 from micro/unlock
unlock before sending the message to avoid deadlock
This commit is contained in:
commit
48a3e51aca
@ -963,26 +963,32 @@ func (n *network) close() error {
|
|||||||
|
|
||||||
// Close closes network connection
|
// Close closes network connection
|
||||||
func (n *network) Close() error {
|
func (n *network) Close() error {
|
||||||
|
// lock this operation
|
||||||
n.Lock()
|
n.Lock()
|
||||||
defer n.Unlock()
|
|
||||||
|
|
||||||
if !n.connected {
|
if !n.connected {
|
||||||
|
n.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-n.closed:
|
case <-n.closed:
|
||||||
|
n.Unlock()
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
|
// TODO: send close message to the network channel
|
||||||
|
close(n.closed)
|
||||||
|
// set connected to false
|
||||||
|
n.connected = false
|
||||||
|
|
||||||
|
// unlock the lock otherwise we'll deadlock sending the close
|
||||||
|
n.Unlock()
|
||||||
|
|
||||||
// send close message only if we managed to connect to NetworkChannel
|
// send close message only if we managed to connect to NetworkChannel
|
||||||
log.Debugf("Sending close message from: %s", n.options.Id)
|
log.Debugf("Sending close message from: %s", n.options.Id)
|
||||||
if err := n.sendMsg("close", NetworkChannel); err != nil {
|
if err := n.sendMsg("close", NetworkChannel); err != nil {
|
||||||
log.Debugf("Network failed to send close message: %s", err)
|
log.Debugf("Network failed to send close message: %s", err)
|
||||||
}
|
}
|
||||||
// TODO: send close message to the network channel
|
|
||||||
close(n.closed)
|
|
||||||
// set connected to false
|
|
||||||
n.connected = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return n.close()
|
return n.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user