mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-29 03:41:45 +00:00
tcp_peer: Fix possible goroutine leak
Scenario: 1. Two messages were read from the connection `p.conn` 2. The first message has started to be processed 3. The second message was queued to be added to the channel `p.incoming` 4. Processing of the first message failed with an error 5. TCP peer is closed, but processing of the second message continues Signed-off-by: Dmitrii Stepanov <dima-stepan@yandex.ru>
This commit is contained in:
parent
327e766cd9
commit
6147bf452a
1 changed files with 6 additions and 1 deletions
|
@ -164,6 +164,7 @@ func (p *TCPPeer) handleConn() {
|
|||
err = p.SendVersion()
|
||||
if err == nil {
|
||||
r := io.NewBinReaderFromIO(p.conn)
|
||||
loop:
|
||||
for {
|
||||
msg := &Message{StateRootInHeader: p.server.config.StateRootInHeader}
|
||||
err = msg.Decode(r)
|
||||
|
@ -174,7 +175,11 @@ func (p *TCPPeer) handleConn() {
|
|||
} else if err != nil {
|
||||
break
|
||||
}
|
||||
p.incoming <- msg
|
||||
select {
|
||||
case p.incoming <- msg:
|
||||
case <-p.done:
|
||||
break loop
|
||||
}
|
||||
}
|
||||
}
|
||||
p.Disconnect(err)
|
||||
|
|
Loading…
Reference in a new issue