Fix deadlock when checking whether to send keep alive
This commit is contained in:
parent
a3c2d76b4a
commit
16c4b08885
|
@ -79,14 +79,16 @@ func (cn *peerConnMsgWriter) run(keepAliveTimeout time.Duration) {
|
|||
if cn.closed.IsSet() {
|
||||
return
|
||||
}
|
||||
keepAlive := false
|
||||
if cn.writeBuffer.Len() == 0 {
|
||||
func() {
|
||||
cn.mu.Unlock()
|
||||
defer cn.mu.Lock()
|
||||
cn.fillWriteBuffer()
|
||||
keepAlive = cn.keepAlive()
|
||||
}()
|
||||
}
|
||||
if cn.writeBuffer.Len() == 0 && time.Since(lastWrite) >= keepAliveTimeout && cn.keepAlive() {
|
||||
if cn.writeBuffer.Len() == 0 && time.Since(lastWrite) >= keepAliveTimeout && keepAlive {
|
||||
cn.writeBuffer.Write(pp.Message{Keepalive: true}.MustMarshalBinary())
|
||||
torrent.Add("written keepalives", 1)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue