alitto / pond

🔘 Minimalistic and High-performance goroutine worker pool written in Go
MIT License
1.43k stars 60 forks source link

panic: send on closed channel, when lots of goroutine are running(may be for a long time) #43

Closed guest6379 closed 1 year ago

guest6379 commented 1 year ago

I'm not quite sure when this issue will happen, but it throws exception as below:

panic: send on closed channel

goroutine 712 [running]:
github.com/alitto/pond.(*WorkerPool).submit(0xc091f93a40, 0xc000536720, 0x1)
        /home/ubuntu/gomods/pkg/mod/github.com/alitto/pond@v1.8.3/pond.go:277 +0x265
github.com/alitto/pond.(*WorkerPool).Submit(...)
        /home/ubuntu/gomods/pkg/mod/github.com/alitto/pond@v1.8.3/pond.go:222
demofiles.Download.func6(0x2?, 0xc000452b60?, 0xc0005fe900?, {0xc000597000, 0x5db, 0x700})
        /home/ubuntu/project1/files/download.go:837 +0x121d
created by demofiles.Download
        /home/ubuntu/project1/files/download.go:820 +0x2125
exit status 2
    // Submit the task to the tasks channel and wait for it to be picked up by a worker
    p.tasks <- task
    submitted = true
    return
guest6379 commented 1 year ago

https://github.com/alitto/pond/blob/4f20b4cc1f2fe1df6b38af03b1ad3e2bd8608c64/pond.go#L277

alitto commented 1 year ago

Hey @guest6379, if you could provide the code you are using and presents this exception that would be great, to find the root cause. The channel in p.tasks gets closed only when the pool is stopped by calling any of these methods: Stop, StopAndWait or StopAndWaitFor. The error you are seeing may indicate some tasks are being submitted after the pool is stopped. The general recommendation is to stop submitting tasks to the pool before stopping the worker pool, to avoid these errors.

alitto commented 1 year ago

Closing due to inactivity