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

Fix promise sync in bool_waiter; rename to callback_waiter #48

Merged
merged 1 commit into from Sep 22, 2023

Conversation

jagerman
Copy link
Member

@jagerman jagerman commented Sep 21, 2023

We were setting the promise in bool_waiter before we call the wrapped lambda, but that introduces a race condition because we have test code that waits on the promise and then checks a value that it expects to have been set inside the lambda.

This reverses it so that the promise is set after the lambda is called.

While here, I also refactored this to a promise<void> since we are never actually meaningfully using the bool value (it is only ever set to true) and removed the get() function (since the only difference between it and wait_ready() is that get() can hang forever), and then since it isn't a "bool" waiter anymore, renamed the whole thing to callback_waiter.

Edit: also renamed wait_ready to wait

Also documented its usage.

tests/utils.hpp Outdated Show resolved Hide resolved
@jagerman
Copy link
Member Author

Rebased on top of #47.

We were setting the promise in bool_waiter *before* we call the wrapped
lambda, but that introduces a race condition because we have test code
that waits on the promise and then checks a value that it expects to
have been set inside the lambda.

This reverses it so that the promise is set *after* the lambda is
called, which should solve the intermittent failure of the 009 test
caused by exactly this race condition.

While here, I also refactored this to a `promise<void>` since we are
never actually meaningfully using the `bool` value (which either returns
true, or hangs), and then since it isn't a "bool" waiter anymore,
renamed to callback_waiter.

`get` doesn't seem useful (it basically is a return-or-hang), so I removed it.

`wait_ready()` felt too long, so I shortened it to `wait()`.

Also adds documentation of the usage of `bool_waiter`.
@jagerman jagerman merged commit 94f1360 into oxen-io:dev Sep 22, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants