Skip to content

Commit 345f639

Browse files
committed
doc: explain why resetting the timer is fine
1 parent acb4116 commit 345f639

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

session.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,14 @@ func (s *Session) stopKeepalive() {
360360
func (s *Session) extendKeepalive() {
361361
s.keepaliveLock.Lock()
362362
if s.keepaliveTimer != nil && !s.keepaliveActive {
363+
// Don't stop the timer and drain the channel. This is an
364+
// AfterFunc, not a normal timer, and any attempts to drain the
365+
// channel will block forever.
366+
//
367+
// Go will stop the timer for us internally anyways. The docs
368+
// say one must stop the timer before calling reset but that's
369+
// to ensure that the timer doesn't end up firing immediately
370+
// after calling Reset.
363371
s.keepaliveTimer.Reset(s.config.KeepAliveInterval)
364372
}
365373
s.keepaliveLock.Unlock()

0 commit comments

Comments
 (0)