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: use more appropriate context-entered check #15691

Closed
wants to merge 1 commit into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Sep 29, 2017

Make the context check in MakeCallback match what the comment says
(and what actually makes sense).

Fixes: #15672
Ref: #15428
Ref: f27b5e4

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

src

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Sep 29, 2017
@addaleax addaleax added backport-requested-v8.x lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 29, 2017
Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

LGTM if CI passes.

@addaleax
Copy link
Member Author

@bnoordhuis
Copy link
Member

I can't say this looks correct to me. It lets you call MakeCallback() with a different context than the one the Environment belongs to.

The problem is the env->AssignToContext(ctx) call in src/node_contextify.cc. In retrospect, I'd say that was an ill thought-out hack that destroyed the 1-to-1 relationship between contexts and environments.

(No concrete proposal on what to change, just food for thought.)

@refack
Copy link
Contributor

refack commented Sep 29, 2017

I can't say this looks correct to me. It lets you call MakeCallback() with a different context than the one the Environment belongs to.

I had a similar thought, but I figured that it's not that the assertion is incorrect, IMHO it's incomplete.
What's more obvious is that the previous assertion was too strict.

@addaleax
Copy link
Member Author

@bnoordhuis Do you think you’d like something along the lines of CHECK_EQ(Environment::GetCurrent(env->isolate()->GetCurrentContext()), env); better? i.e. checking that the context belongs to the Environment?

@bnoordhuis
Copy link
Member

Not perfect perhaps but better. You can write it as CHECK_EQ(Environment::GetCurrent(env->isolate()), env);, it does the same thing.

Ideally, each context gets its own environment. That would avoid issues like #15673.

What's more obvious is that the previous assertion was too strict.

For background, it was just right when it was introduced, it's that the code base evolved afterwards.

Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

Fixes: nodejs#15672
Ref: nodejs#15428
Ref: f27b5e4
@addaleax
Copy link
Member Author

addaleax commented Oct 2, 2017

@bnoordhuis I’ve updated with that. I see why you might not really be a fan, and if you prefer a much more comprehensive rewrite as a solution that should be fine, but imho this is just fine as a “does not crash anymore” kind of solution.

@addaleax
Copy link
Member Author

addaleax commented Oct 7, 2017

@addaleax
Copy link
Member Author

addaleax commented Oct 8, 2017

Landed in 037d908

@addaleax addaleax closed this Oct 8, 2017
@addaleax addaleax deleted the async-hooks-context-check branch October 8, 2017 21:21
addaleax added a commit that referenced this pull request Oct 8, 2017
Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

PR-URL: #15691
Fixes: #15672
Ref: #15428
Ref: f27b5e4
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
addaleax added a commit to addaleax/ayo that referenced this pull request Oct 12, 2017
Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

PR-URL: nodejs/node#15691
Fixes: nodejs/node#15672
Ref: nodejs/node#15428
Ref: f27b5e4bdaafc73a830a0451ee3c641b8bcd08fe
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
addaleax added a commit to addaleax/node that referenced this pull request Oct 14, 2017
Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

PR-URL: nodejs#15691
Fixes: nodejs#15672
Ref: nodejs#15428
Ref: f27b5e4
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
targos pushed a commit that referenced this pull request Oct 18, 2017
Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

PR-URL: #15691
Fixes: #15672
Ref: #15428
Ref: f27b5e4
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
targos pushed a commit that referenced this pull request Oct 18, 2017
Make the context check in `MakeCallback` match what the comment says
(and what actually makes sense).

PR-URL: #15691
Fixes: #15672
Ref: #15428
Ref: f27b5e4
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Eugene Ostroukhov <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
@MylesBorins
Copy link
Contributor

should this land on v6.x

@MylesBorins
Copy link
Contributor

ping @addaleax

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants