panic: send on closed channel
waffleboot opened this issue · comments
goroutine 33 [running]:
github.com/ahmetask/worker.(*Pool).EnqueueWithTimeout.func1()
/root/go/src/github com/ahmetask/worker/dispatcher.go:106 +0x36
created by time.goFunc
/usr/local/go/src/time/sleep.go:166 +0x45
test case:
q.internalQueue <- job
return
run defer
t.Stop()
close(ch)
at the same time timer is fired just by timeout. It's race condition: defer vs timer's func
ch <- false // but ch is closed yet
timer.Stop doesn't stop timer really, it marks it as stopped only and timer will be deleted by goroutine that created that timer.
thanks we can delete close(ch) and leave it to the gc