mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
network: handle errors and connection close more correctly
This makes writer side handle errors properly and fixes communication between reader and writer goroutine to always correctly unregister the peer. This is especially important for the case where error occurs before handshake completes as in this case we don't even have goroutine in startProtocol() running.
This commit is contained in:
parent
76c7cff67f
commit
d3bb8ddf8f
3 changed files with 45 additions and 26 deletions
|
@ -136,7 +136,12 @@ func (p *TCPPeer) Done() chan error {
|
|||
// Disconnect will fill the peer's done channel with the given error.
|
||||
func (p *TCPPeer) Disconnect(err error) {
|
||||
p.conn.Close()
|
||||
p.done <- err
|
||||
select {
|
||||
case p.done <- err:
|
||||
// one message to the queue
|
||||
default:
|
||||
// the other side may already be gone, it's OK
|
||||
}
|
||||
}
|
||||
|
||||
// Version implements the Peer interface.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue