mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-05-28 13:41:20 +00:00
fix race condition where we might not close an opened stream.
This commit is contained in:
parent
a1b973ce3c
commit
13a847a8bb
11
notif.go
11
notif.go
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user