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

Fix race condition when waiting for functions #304

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

meyerj
Copy link
Member

@meyerj meyerj commented Aug 1, 2019

Without the added lock of the message mutex it can happen that the calling thread wakes up and checks the completion condition in waitForMessagesInternal(), but the runner engine finishes and signals the condition variable in processFunctions() before the calling thread enters waiting state again.

This is a race condition and it is hard to catch it in a unit test.

This lock was already introduced in 58cb4bb as part of #91, but has been reverted in b9f2f34 before the merge. There was a comment in psoetens#3 (comment) that explains why the revert was needed, which also leaves the question open whether to keep the lock in processFunctions():

The interesting part is the comment in processMessages(). Maybe something similar was the case in processFunctions() and this is the only lock that was really required?

Without the added lock of the message mutex it can happen that the calling thread wakes up and checks the completion
condition in waitForMessagesInternal(), but the runner engine finishes and signals the condition variable
in processFunctions() before the calling thread enters waiting state again.

Signed-off-by: Johannes Meyer <johannes@intermodalics.eu>
@meyerj meyerj added the bug label Aug 1, 2019
@meyerj meyerj added this to the 2.9 milestone Aug 1, 2019
@meyerj meyerj merged commit 058536d into master Oct 21, 2019
@meyerj meyerj deleted the fix-race-condition-when-waiting-for-functions branch October 21, 2019 16:18
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant