Browse Source

do not block when writing to pongTimeoutCh

Refs #1205
pull/1209/head
Anton Kaliaev 7 years ago
parent
commit
fc585bcdec
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 7 additions and 15 deletions
  1. +7
    -15
      p2p/conn/connection.go

+ 7
- 15
p2p/conn/connection.go View File

@ -201,12 +201,12 @@ func (c *MConnection) OnStart() error {
// OnStop implements BaseService
func (c *MConnection) OnStop() {
c.BaseService.OnStop()
if c.quit != nil {
close(c.quit)
}
c.flushTimer.Stop()
c.pingTimer.Stop()
c.chStatsTimer.Stop()
if c.quit != nil {
close(c.quit)
}
c.conn.Close() // nolint: errcheck
// We can't close pong safely here because
@ -339,7 +339,10 @@ FOR_LOOP:
c.sendMonitor.Update(int(n))
c.Logger.Debug("Starting pong timer", "dur", c.config.PongTimeout)
c.pongTimer = time.AfterFunc(c.config.PongTimeout, func() {
c.pongTimeoutCh <- true
select {
case c.pongTimeoutCh <- true:
default:
}
})
c.flush()
case timeout := <-c.pongTimeoutCh:
@ -548,7 +551,6 @@ func (c *MConnection) stopPongTimer() {
if !c.pongTimer.Stop() {
<-c.pongTimer.C
}
drain(c.pongTimeoutCh)
c.pongTimer = nil
}
}
@ -780,13 +782,3 @@ 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 bool) {
for {
select {
case <-ch:
default:
return
}
}
}

Loading…
Cancel
Save