mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 21:39:25 +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:
parent
b003cd6287
commit
2e8a98a925
@ -133,10 +133,12 @@ func (socket *Socket) Write(data string) error {
|
|||||||
|
|
||||||
// timedFillLineToSendExists either sends the note or times out.
|
// timedFillLineToSendExists either sends the note or times out.
|
||||||
func (socket *Socket) timedFillLineToSendExists(duration time.Duration) {
|
func (socket *Socket) timedFillLineToSendExists(duration time.Duration) {
|
||||||
|
lineToSendTimeout := time.NewTimer(duration)
|
||||||
|
defer lineToSendTimeout.Stop()
|
||||||
select {
|
select {
|
||||||
case socket.lineToSendExists <- true:
|
case socket.lineToSendExists <- true:
|
||||||
// passed data successfully
|
// passed data successfully
|
||||||
case <-time.After(duration):
|
case <-lineToSendTimeout.C:
|
||||||
// timed out send
|
// timed out send
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user