Skip to content

Commit feb3cb9

Browse files
committed
robustsession: do not write to session after it was deleted
stopAndMaybeNotify() is not safe to call after the robustsession was deleted, as notifications are written to the robustsession’s channel, which is closed. Instead, use stopWithoutNotifying() after session deletion.
1 parent 756cf32 commit feb3cb9

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

robustsession/robustsession.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,16 @@ func (us *unavailabilityState) start() {
543543
})
544544
}
545545

546-
func (us *unavailabilityState) stopAndMaybeNotify() {
546+
func (us *unavailabilityState) stopWithoutNotifying() {
547547
if us.timer == nil {
548548
return
549549
}
550550
us.timer.Stop()
551551
us.timer = nil
552+
}
553+
554+
func (us *unavailabilityState) stopAndMaybeNotify() {
555+
us.stopWithoutNotifying()
552556
if us.hasNotified() {
553557
us.session.injectUnavailabilityMessage("RobustIRC connectivity restored!")
554558
}
@@ -693,7 +697,7 @@ func (s *RobustSession) getMessages() {
693697
// server fails.
694698
time.Sleep(time.Duration(250+rand.Int63n(250)) * time.Millisecond)
695699
}
696-
unavailability.stopAndMaybeNotify()
700+
unavailability.stopWithoutNotifying()
697701
}
698702

699703
// SessionId returns a string that identifies the session. It should be used in

0 commit comments

Comments
 (0)