defer stream removal instead of doing it inline.
This commit is contained in:
parent
b080f595bb
commit
9e129db766
14
comm.go
14
comm.go
|
@ -52,6 +52,14 @@ func (p *PubSub) handleNewStream(s network.Stream) {
|
||||||
p.inboundStreams[peer] = s
|
p.inboundStreams[peer] = s
|
||||||
p.inboundStreamsMx.Unlock()
|
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)
|
r := protoio.NewDelimitedReader(s, p.maxMessageSize)
|
||||||
for {
|
for {
|
||||||
rpc := new(RPC)
|
rpc := new(RPC)
|
||||||
|
@ -66,12 +74,6 @@ func (p *PubSub) handleNewStream(s network.Stream) {
|
||||||
s.Close()
|
s.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
p.inboundStreamsMx.Lock()
|
|
||||||
if p.inboundStreams[peer] == s {
|
|
||||||
delete(p.inboundStreams, peer)
|
|
||||||
}
|
|
||||||
p.inboundStreamsMx.Unlock()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue