Skip to content

Commit

Permalink
conn: don't spam draining cleanup log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mreiferson committed Oct 26, 2014
1 parent bc8c7b6 commit 1b61ac6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func (c *Conn) close() {
func (c *Conn) cleanup() {
<-c.drainReady
ticker := time.NewTicker(100 * time.Millisecond)
lastWarning := time.Now()
// writeLoop has exited, drain any remaining in flight messages
for {
// we're racing with readLoop which potentially has a message
Expand All @@ -635,13 +636,19 @@ func (c *Conn) cleanup() {
msgsInFlight = atomic.LoadInt64(&c.messagesInFlight)
}
if msgsInFlight > 0 {
c.log(LogLevelWarning, "draining... waiting for %d messages in flight", msgsInFlight)
if time.Now().Sub(lastWarning) > time.Second {
c.log(LogLevelWarning, "draining... waiting for %d messages in flight", msgsInFlight)
lastWarning = time.Now()
}
continue
}
// until the readLoop has exited we cannot be sure that there
// still won't be a race
if atomic.LoadInt32(&c.readLoopRunning) == 1 {
c.log(LogLevelWarning, "draining... readLoop still running")
if time.Now().Sub(lastWarning) > time.Second {
c.log(LogLevelWarning, "draining... readLoop still running")
lastWarning = time.Now()
}
continue
}
goto exit
Expand Down

0 comments on commit 1b61ac6

Please sign in to comment.