diff --git a/conn.go b/conn.go index 82d043e5..1f345318 100644 --- a/conn.go +++ b/conn.go @@ -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 @@ -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