defer stream removal instead of doing it inline.

This commit is contained in:
vyzo 2021-01-12 16:26:38 +02:00
parent b080f595bb
commit 9e129db766
1 changed files with 8 additions and 6 deletions

14
comm.go
View File

@ -52,6 +52,14 @@ func (p *PubSub) handleNewStream(s network.Stream) {
p.inboundStreams[peer] = s
p.inboundStreamsMx.Unlock()
defer func() {
p.inboundStreamsMx.Lock()
if p.inboundStreams[peer] == s {
delete(p.inboundStreams, peer)
}
p.inboundStreamsMx.Unlock()
}()
r := protoio.NewDelimitedReader(s, p.maxMessageSize)
for {
rpc := new(RPC)
@ -66,12 +74,6 @@ func (p *PubSub) handleNewStream(s network.Stream) {
s.Close()
}
p.inboundStreamsMx.Lock()
if p.inboundStreams[peer] == s {
delete(p.inboundStreams, peer)
}
p.inboundStreamsMx.Unlock()
return
}