Skip to content

Commit

Permalink
Merge pull request #5008 from oasisprotocol/peternose/fix/workpool-leak
Browse files Browse the repository at this point in the history
go/common/workerpool: Fix memory leak when workerpool is stopped early
  • Loading branch information
peternose authored Oct 30, 2022
2 parents 978ea30 + a888835 commit f8b22e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changelog/5008.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/common/workerpool: Fix memory leak when workerpool is stopped early

When workerpool si stopped, the job channel might still contain jobs which
haven't been processed. Therefore, the channel never closes and leaves one
go routine hanging.
4 changes: 4 additions & 0 deletions go/common/workerpool/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (p *Pool) Stop() {
p.stopOnce.Do(func() {
close(p.stopCh)
})

for range p.jobCh.Out() {
// Clear the channel to close all go routines and prevent memory leaks.
}
}

// Quit returns a channel that will be closed when the pool stops.
Expand Down

0 comments on commit f8b22e2

Please sign in to comment.