forked from TrueCloudLab/neoneo-go
Merge pull request #2738 from nspcc-dev/dont-block-forever-2
network: don't wait indefinitely for packet to be sent
This commit is contained in:
commit
0294e2eb18
2 changed files with 10 additions and 3 deletions
|
@ -1385,7 +1385,7 @@ func (s *Server) iteratePeersWithSendMsg(msg *Message, send func(Peer, bool, []b
|
||||||
peer.AddGetAddrSent()
|
peer.AddGetAddrSent()
|
||||||
}
|
}
|
||||||
sentN++
|
sentN++
|
||||||
} else if errors.Is(err, errBusy) {
|
} else if !blocking && errors.Is(err, errBusy) {
|
||||||
// Can be retried.
|
// Can be retried.
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -87,11 +87,18 @@ func (p *TCPPeer) putPacketIntoQueue(queue chan<- []byte, block bool, msg []byte
|
||||||
if !p.Handshaked() {
|
if !p.Handshaked() {
|
||||||
return errStateMismatch
|
return errStateMismatch
|
||||||
}
|
}
|
||||||
|
var ret error
|
||||||
if block {
|
if block {
|
||||||
|
timer := time.NewTimer(p.server.TimePerBlock / 2)
|
||||||
select {
|
select {
|
||||||
case queue <- msg:
|
case queue <- msg:
|
||||||
case <-p.done:
|
case <-p.done:
|
||||||
return errGone
|
ret = errGone
|
||||||
|
case <-timer.C:
|
||||||
|
ret = errBusy
|
||||||
|
}
|
||||||
|
if !errors.Is(ret, errBusy) && !timer.Stop() {
|
||||||
|
<-timer.C
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
select {
|
select {
|
||||||
|
@ -102,7 +109,7 @@ func (p *TCPPeer) putPacketIntoQueue(queue chan<- []byte, block bool, msg []byte
|
||||||
return errBusy
|
return errBusy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnqueuePacket implements the Peer interface.
|
// EnqueuePacket implements the Peer interface.
|
||||||
|
|
Loading…
Reference in a new issue