3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

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.
This commit is contained in:
Euan Kemp 2017-07-13 23:45:17 -07:00 committed by Daniel Oaks
parent b003cd6287
commit 2e8a98a925

View File

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