Browse Source

ensure the nick timeout mechanism is cleaned up on client quit

tags/v0.11.0-beta
Shivaram Lingamneni 6 years ago
parent
commit
945dec9964
2 changed files with 20 additions and 3 deletions
  1. 2
    3
      irc/client.go
  2. 18
    0
      irc/idletimer.go

+ 2
- 3
irc/client.go View File

@@ -686,9 +686,8 @@ func (client *Client) destroy(beingResumed bool) {
686 686
 	}
687 687
 
688 688
 	// clean up self
689
-	if client.idletimer != nil {
690
-		client.idletimer.Stop()
691
-	}
689
+	client.idletimer.Stop()
690
+	client.nickTimer.Stop()
692 691
 
693 692
 	client.server.accounts.Logout(client)
694 693
 

+ 18
- 0
irc/idletimer.go View File

@@ -127,6 +127,10 @@ func (it *IdleTimer) processTimeout() {
127 127
 
128 128
 // Stop stops counting idle time.
129 129
 func (it *IdleTimer) Stop() {
130
+	if it == nil {
131
+		return
132
+	}
133
+
130 134
 	it.Lock()
131 135
 	defer it.Unlock()
132 136
 	it.state = TimerDead
@@ -232,6 +236,20 @@ func (nt *NickTimer) Touch() {
232 236
 	}
233 237
 }
234 238
 
239
+// Stop stops counting time and cleans up the timer
240
+func (nt *NickTimer) Stop() {
241
+	if nt == nil {
242
+		return
243
+	}
244
+
245
+	nt.Lock()
246
+	defer nt.Unlock()
247
+	if nt.timer != nil {
248
+		nt.timer.Stop()
249
+		nt.timer = nil
250
+	}
251
+}
252
+
235 253
 func (nt *NickTimer) sendWarning() {
236 254
 	baseNotice := "Nickname is reserved; you must change it or authenticate to NickServ within %v"
237 255
 	nt.client.Notice(fmt.Sprintf(nt.client.t(baseNotice), nt.timeout))

Loading…
Cancel
Save