mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-27 05:42:56 +00:00
network: move Version sending to the tcp transport
We have a race between reader and writer goroutines for the same connection that leads to handshake failures when reader is faster to read the incoming version (and try to reply to it) than writer is to write our own Version: WARN[0000] peer disconnected addr="172.200.0.4:20334" peerCount=5 reason="invalid handshake: tried to send VersionAck, but didn't send Version yet Fix it by moving Version sending before the reader loop starts.
This commit is contained in:
parent
2d41450ac9
commit
734338ad70
2 changed files with 6 additions and 6 deletions
|
@ -200,12 +200,6 @@ func (s *Server) run() {
|
|||
}
|
||||
return
|
||||
case p := <-s.register:
|
||||
// When a new peer is connected we send out our version immediately.
|
||||
if err := s.sendVersion(p); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"addr": p.RemoteAddr(),
|
||||
}).Error(err)
|
||||
}
|
||||
s.lock.Lock()
|
||||
s.peers[p] = true
|
||||
s.lock.Unlock()
|
||||
|
|
|
@ -78,6 +78,12 @@ func (t *TCPTransport) handleConn(conn net.Conn) {
|
|||
|
||||
t.server.register <- p
|
||||
|
||||
// When a new peer is connected we send out our version immediately.
|
||||
if err := t.server.sendVersion(p); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"addr": p.RemoteAddr(),
|
||||
}).Error(err)
|
||||
}
|
||||
r := io.NewBinReaderFromIO(p.conn)
|
||||
for {
|
||||
msg := &Message{}
|
||||
|
|
Loading…
Reference in a new issue