Commit 13a847a8 authored by Steven Allen's avatar Steven Allen

fix race condition where we might not close an opened stream.

parent a1b973ce
...@@ -55,24 +55,21 @@ func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) { ...@@ -55,24 +55,21 @@ func (nn *netNotifiee) Connected(n inet.Network, v inet.Conn) {
for { for {
s, err := dht.host.NewStream(ctx, v.RemotePeer(), ProtocolDHT, ProtocolDHTOld) s, err := dht.host.NewStream(ctx, v.RemotePeer(), ProtocolDHT, ProtocolDHTOld)
// Canceled.
if ctx.Err() != nil {
return
}
switch err { switch err {
case nil: case nil:
s.Close() s.Close()
dht.plk.Lock() dht.plk.Lock()
defer dht.plk.Unlock() defer dht.plk.Unlock()
// Check if canceled again under the lock. // Check if canceled under the lock.
if ctx.Err() == nil { if ctx.Err() == nil {
dht.Update(dht.Context(), v.RemotePeer()) dht.Update(dht.Context(), v.RemotePeer())
} }
case io.EOF: case io.EOF:
// Connection died but we may still have *an* open connection so try again. if ctx.Err() == nil {
// Connection died but we may still have *an* open connection (context not canceled) so try again.
continue continue
}
case mstream.ErrNotSupported: case mstream.ErrNotSupported:
// Client mode only, don't bother adding them to our routing table // Client mode only, don't bother adding them to our routing table
default: default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment