Browse Source

irc: fix timer memleak

This is a gotcha called out in the `time.After` docs. `time.After` will
leak the underlying channel if nothing ever receives on it.
tags/v0.9.0
Euan Kemp 7 years ago
parent
commit
2e8a98a925
1 changed files with 3 additions and 1 deletions
  1. 3
    1
      irc/socket.go

+ 3
- 1
irc/socket.go View File

@@ -133,10 +133,12 @@ func (socket *Socket) Write(data string) error {
133 133
 
134 134
 // timedFillLineToSendExists either sends the note or times out.
135 135
 func (socket *Socket) timedFillLineToSendExists(duration time.Duration) {
136
+	lineToSendTimeout := time.NewTimer(duration)
137
+	defer lineToSendTimeout.Stop()
136 138
 	select {
137 139
 	case socket.lineToSendExists <- true:
138 140
 		// passed data successfully
139
-	case <-time.After(duration):
141
+	case <-lineToSendTimeout.C:
140 142
 		// timed out send
141 143
 	}
142 144
 }

Loading…
Cancel
Save