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 race conditions with functions returning "no output" #102

Merged
merged 3 commits into from
Nov 19, 2020

Conversation

danielhenrymantilla
Copy link
Contributor

The current implementation of #[node_bindgen] wrapping shim over async fn functions special cased those with no return value to return immediately. This meant that if such an async fn had a side-effect that following-up code wanted to observe, there would be a race condition whereby such code could observe causally-inconsistent state, leading to logic bugs.

Removing that special-cased branch seems to have fixed the issue.

@danielhenrymantilla
Copy link
Contributor Author

danielhenrymantilla commented Nov 19, 2020

Since the commit getditto@b191ff4 is based off the crates.io release (to reduce the churn from [patch]-ing1 it with a Cargo.toml), I'll rebase the current PR

1 The fix can be tested using…
[patch.crates-io.node-bindgen]
version = "3.0.0"
git = "https://github.com/getditto/node-bindgen"
rev = "b191ff4d671418ee56cc99b75acfd1853cdab6e6"

The current implementation of `#[node_bindgen]` wrapping shim over
`async fn` functions special cased those with no return value
to return immediately, for some reason. This meant that if such
an `async fn` had a side-effect that following-up code wanted to observe,
there would be a race condition whereby such code could observe
causally-inconsitent state, leading to logic bugs.
Copy link
Collaborator

@sehz sehz left a comment

Choose a reason for hiding this comment

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

Thanks for contribution.

After removing cleanup, can you also bump up crate version?

nj-derive/src/generator/context.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@sehz sehz left a comment

Choose a reason for hiding this comment

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

Great.

@sehz sehz merged commit 8632359 into infinyon:master Nov 19, 2020
@sehz sehz linked an issue Nov 19, 2020 that may be closed by this pull request
nickbabcock added a commit to nickbabcock/node-bindgen that referenced this pull request Nov 19, 2020
This commit adds the test case component to infinyon#102 to ensure that this behavior
is not regressed on.
sehz pushed a commit that referenced this pull request Nov 20, 2020
This commit adds the test case component to #102 to ensure that this behavior
is not regressed on.
@danielhenrymantilla danielhenrymantilla deleted the dhm/fix-async-fn-no-output branch November 20, 2020 13:58
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.

Async functions without return values are resolved immediately
2 participants