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

src: fix crash on FSReqPromise destructor #43533

Merged
merged 1 commit into from
Jul 9, 2022

Conversation

santigimeno
Copy link
Member

We are deciding whether to end fs promises by checking
can_call_into_js() whereas in the FSReqPromise destructor we're
using the is_stopping() check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on Environment::ExitEnv() and both are atomic they are not
synchronized together so it may happen that when reaching the destructor
call_into_js may be set to false whereas is_stopping remains
false causing the crash. Fix this by using the same checks everywhere.

Fixes: #43499

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 22, 2022
@santigimeno
Copy link
Member Author

santigimeno commented Jun 22, 2022

/cc @addaleax as you already commented in the original PR. Do you think this is the correct approach or just use the can_call_into_js() everywhere? Thanks

@addaleax
Copy link
Member

Do you think this is the correct approach or just use the can_call_into_js() everywhere?

I’d turn the line in the destructor into CHECK_IMPLIES(!finished_, !env()->can_call_into_js());, yeah. During the original review I missed that this is about checking that the precondition for not finishing (which should be !env->can_call_into_js()) was fulfilled if the promise wasn’t finished, rather than being a standalone check that was unrelated to the other conditionals introduced in the original PR.

We are deciding whether to end `fs` promises by checking
`can_call_into_js()` whereas in the `FSReqPromise` destructor we're
using the `is_stopping()` check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on `Environment::ExitEnv()` and both are atomic they are not
syncronized together so it may happen that when reaching the destructor
`call_into_js` may be set to `false` whereas `is_stopping` remains
`false` causing the crash. Fix this by checking with
`can_call_into_js()` also in the destructor.

Fixes: nodejs#43499
@santigimeno
Copy link
Member Author

@addaleax I've updated the PR with your suggestion. Thanks!!
While we're here, one question if you don't mind: I understand the difference in semantics between stopping and can_call_into_js but while looking at where and when they're set it's not completely clear to me why they can't be folded into one variable. Could you clarify it? Thanks in advance

@santigimeno santigimeno added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 22, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 22, 2022
@nodejs-github-bot

This comment was marked as outdated.

@addaleax
Copy link
Member

I understand the difference in semantics between stopping and can_call_into_js but while looking at where and when they're set it's not completely clear to me why they can't be folded into one variable. Could you clarify it? Thanks in advance

I think that is potentially possible for sure, but as you mention, there is a difference in semantics. I could imagine us setting can_call_into_js to false temporarily if we introduce a DisallowJavascriptExecutionScope at some point, for example, but that shouldn’t affect is_stopping.

@santigimeno santigimeno added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 23, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 23, 2022
@nodejs-github-bot

This comment was marked as outdated.

@F3n67u F3n67u added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 25, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 25, 2022
@nodejs-github-bot

This comment was marked as outdated.

@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 26, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 26, 2022
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@RaisinTen
Copy link
Contributor

The Jenkins CI attempts to rebase before running the tests, so a manual rebase is not strictly necessary.

@F3n67u
Copy link
Member

F3n67u commented Jun 29, 2022

The Jenkins CI attempts to rebase before running the tests, so a manual rebase is not strictly necessary.

I dont know that. Thanks for the info. Then let us rerun the ci and see if ci is happy now.

@F3n67u F3n67u added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2022
@nodejs-github-bot

This comment was marked as outdated.

@F3n67u F3n67u added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2022
@nodejs-github-bot

This comment was marked as outdated.

@F3n67u F3n67u added flaky-test Issues and PRs related to the tests with unstable failures on the CI. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Jun 30, 2022
@F3n67u
Copy link
Member

F3n67u commented Jul 3, 2022

Hi, collaborators. could you help to trigger another resume ci run?

The last ci failure is mainly caused by flaky test-stream-finished. This test is already fixed by #43641. we could trigger another ci run.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 9, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 9, 2022
@nodejs-github-bot nodejs-github-bot merged commit 92d26e7 into nodejs:main Jul 9, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 92d26e7

targos pushed a commit that referenced this pull request Jul 12, 2022
We are deciding whether to end `fs` promises by checking
`can_call_into_js()` whereas in the `FSReqPromise` destructor we're
using the `is_stopping()` check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on `Environment::ExitEnv()` and both are atomic they are not
syncronized together so it may happen that when reaching the destructor
`call_into_js` may be set to `false` whereas `is_stopping` remains
`false` causing the crash. Fix this by checking with
`can_call_into_js()` also in the destructor.

Fixes: #43499

PR-URL: #43533
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jul 20, 2022
We are deciding whether to end `fs` promises by checking
`can_call_into_js()` whereas in the `FSReqPromise` destructor we're
using the `is_stopping()` check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on `Environment::ExitEnv()` and both are atomic they are not
syncronized together so it may happen that when reaching the destructor
`call_into_js` may be set to `false` whereas `is_stopping` remains
`false` causing the crash. Fix this by checking with
`can_call_into_js()` also in the destructor.

Fixes: #43499

PR-URL: #43533
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this pull request Jul 31, 2022
We are deciding whether to end `fs` promises by checking
`can_call_into_js()` whereas in the `FSReqPromise` destructor we're
using the `is_stopping()` check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on `Environment::ExitEnv()` and both are atomic they are not
syncronized together so it may happen that when reaching the destructor
`call_into_js` may be set to `false` whereas `is_stopping` remains
`false` causing the crash. Fix this by checking with
`can_call_into_js()` also in the destructor.

Fixes: #43499

PR-URL: #43533
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
We are deciding whether to end `fs` promises by checking
`can_call_into_js()` whereas in the `FSReqPromise` destructor we're
using the `is_stopping()` check. Though this may look as semantically
correct it has issues because though both values are modified before
termination on `Environment::ExitEnv()` and both are atomic they are not
syncronized together so it may happen that when reaching the destructor
`call_into_js` may be set to `false` whereas `is_stopping` remains
`false` causing the crash. Fix this by checking with
`can_call_into_js()` also in the destructor.

Fixes: nodejs/node#43499

PR-URL: nodejs/node#43533
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. flaky-test Issues and PRs related to the tests with unstable failures on the CI. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
Projects
None yet
8 participants