Skip to content
New issue

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

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

Already on GitHub? # to your account

readdb: fix deadlock in Run method #58

Merged
merged 1 commit into from
Jul 23, 2019

Conversation

sgotti
Copy link
Member

@sgotti sgotti commented Jul 23, 2019

In runservice readdb Run method we could end with a deadlock if two of the
goroutines that call HandleEvents.* try to write to the errCh at the same
time before the errCh is read. If this happens one of the two will be blocked on
writing to the channel but the read won't happen since it'll blocked by
wg.Wait().

Fix this doing:

  • use a buffered channel large as the number of executed goroutines.
  • create a new errCh at every loop (so we'll ignore later errors after the first
    one)

Note: we could also use a non blocking send to avoid this situation but we
should also start the wg.Wait before the goroutines or earlier errors could be
lost causing another kind of hang.

In runservice readdb Run method we could end with a deadlock if two of the
goroutines that call HandleEvents.* try to write to the errCh at the same
time before the errCh is read. If this happens one of the two will be blocked on
writing to the channel but the read won't happen since it'll blocked by
wg.Wait().

Fix this doing:
* use a buffered channel large as the number of executed goroutines.
* create a new errCh at every loop (so we'll ignore later errors after the first
one)

Note: we could also use a non blocking send to avoid this situation but we
should also start the wg.Wait before the goroutines or earlier errors could be
lost causing another kind of hang.
@sgotti sgotti merged commit 77ee8d9 into agola-io:master Jul 23, 2019
@sgotti sgotti deleted the readdb_fix_deadlock branch February 19, 2020 09:07
tulliobotti64 pushed a commit to tulliobotti64/agola that referenced this pull request Oct 19, 2022
tulliobotti64 pushed a commit to tulliobotti64/agola that referenced this pull request Oct 19, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant