Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitgroup sync fix #37

Merged
merged 4 commits into from
May 20, 2022
Merged

waitgroup sync fix #37

merged 4 commits into from
May 20, 2022

Conversation

kaworu
Copy link
Member

@kaworu kaworu commented May 19, 2022

See commits, the most important one is the last one workerpool: WaitGroup synchronization fix.

@kaworu kaworu added the kind/bug Something isn't working label May 19, 2022
@kaworu kaworu requested review from tklauser and rolinh May 19, 2022 15:57
Copy link
Member

@tklauser tklauser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment about golangci-lint version, all other commits LGTM. Thanks.

@kaworu kaworu force-pushed the pr/kaworu/waitgroup-sync-fix branch from e7cacc4 to fa320d0 Compare May 20, 2022 08:02
@kaworu kaworu requested a review from tklauser May 20, 2022 08:02
@kaworu kaworu force-pushed the pr/kaworu/waitgroup-sync-fix branch from fa320d0 to ef0b159 Compare May 20, 2022 08:03
kaworu added 3 commits May 20, 2022 10:04
Signed-off-by: Alexandre Perrin <alex@kaworu.ch>
Bring workerpool in line with how license / copyright is handled in
Cilium, see cilium/cilium#18813 for more
context.

Signed-off-by: Alexandre Perrin <alex@kaworu.ch>
Drain() doesn't submit any task.

Signed-off-by: Alexandre Perrin <alex@kaworu.ch>
@kaworu kaworu force-pushed the pr/kaworu/waitgroup-sync-fix branch from ef0b159 to f5473ba Compare May 20, 2022 09:48
Before this patch, Submit() would increment the WaitGroup without
holding the WorkerPool lock. This could potentially lead to a panic when
Submit() and Close() were executed concurrently:

1. The Submit() goroutine g0 acquire the lock, successfully check that
   the WorkerPool is neither closed nor draining, and release the lock.
2. The Close() goroutine g1 acquire the lock, update the WorkerPool
   state to closed, wait on the WaitGroup, and close the tasks channel
   (wrongly) assuming that all tasks have been submitted.
3. g0 increment the WaitGroup, and attempt to write to the (now closed)
   tasks channel leading to a panic.

The same reasoning can be applied with Submit() and Drain() leading to a
data race on the results slice.

Signed-off-by: Alexandre Perrin <alex@kaworu.ch>
@kaworu kaworu merged commit 90fa389 into master May 20, 2022
@kaworu kaworu deleted the pr/kaworu/waitgroup-sync-fix branch May 20, 2022 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants