Browse Source

drain pongTimeoutCh and pongTimer's channel to prevent leaks

pull/1095/head
Anton Kaliaev 6 years ago
parent
commit
ac0123d249
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 18 additions and 2 deletions
  1. +18
    -2
      p2p/conn/connection.go

+ 18
- 2
p2p/conn/connection.go View File

@ -352,7 +352,10 @@ FOR_LOOP:
c.flush()
case <-c.quit:
if c.pongTimer != nil {
_ = c.pongTimer.Stop()
if !c.pongTimer.Stop() {
<-c.pongTimer.C
}
drain(c.pongTimeoutCh)
}
break FOR_LOOP
case <-c.send:
@ -488,7 +491,10 @@ FOR_LOOP:
case packetTypePong:
c.Logger.Debug("Receive Pong")
if c.pongTimer != nil {
_ = c.pongTimer.Stop()
if !c.pongTimer.Stop() {
<-c.pongTimer.C
}
drain(c.pongTimeoutCh)
}
case packetTypeMsg:
pkt, n, err := msgPacket{}, int(0), error(nil)
@ -764,3 +770,13 @@ type msgPacket struct {
func (p msgPacket) String() string {
return fmt.Sprintf("MsgPacket{%X:%X T:%X}", p.ChannelID, p.Bytes, p.EOF)
}
func drain(ch <-chan struct{}) {
for {
select {
case <-ch:
default:
return
}
}
}

Loading…
Cancel
Save