-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 async hooks crashing when there is no node context #19134
Closed
Closed
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
6b76017
src: fix async hooks crashing when there is no node context
xaviergonz 84a1822
src: optimization for check for env promise hook
xaviergonz 5e9128f
src: fixed linting errors for env.cc
xaviergonz 9690b86
fix: updated with the latest code review
xaviergonz 0e4fda8
fix: made the magic number smaller and a constant
xaviergonz c938269
fix: switched back to promise creation context
xaviergonz 70169d3
fix: using a faster way to know if we are in a node context
xaviergonz 9f69beb
Merge pull request #1 from nodejs/master
xaviergonz 96a53db
Merge branch 'master' into fix-async-hooks-crash
xaviergonz cb3bba1
fix: rebase to latest master and use node_context_data constants
xaviergonz 51257ed
fix: added namespace for enum
xaviergonz 361d425
fix: storing actual pointers on the context
xaviergonz 704b418
Merge branch 'master' into fix-async-hooks-crash
xaviergonz bca7fd1
src: code review
xaviergonz 0577c29
fix: code review changes
xaviergonz 54bf6dc
fix: code review
xaviergonz 3c4d991
fix: code review changes
xaviergonz 4d20b72
fix: code review
xaviergonz d9214a7
Merge branch 'master' into fix-async-hooks-crash
xaviergonz 23fa418
src: fix async hooks crashing when there is no node context
xaviergonz c2b9b32
src: optimization for check for env promise hook
xaviergonz 4437f90
src: fixed linting errors for env.cc
xaviergonz 436919e
fix: updated with the latest code review
xaviergonz 6b095d7
fix: made the magic number smaller and a constant
xaviergonz 85cf945
fix: switched back to promise creation context
xaviergonz 76df613
fix: using a faster way to know if we are in a node context
xaviergonz 077c7a5
fix: rebase to latest master and use node_context_data constants
xaviergonz 92ec8c1
fix: added namespace for enum
xaviergonz 39b5c1f
fix: storing actual pointers on the context
xaviergonz 9c72574
src: code review
xaviergonz e91cdc0
fix: code review changes
xaviergonz 6ef891e
fix: code review
xaviergonz 5ac8e62
fix: code review changes
xaviergonz aaa53b1
fix: code review
xaviergonz 3a54578
fix: rebasing
xaviergonz 634a63e
fix: linting errors
xaviergonz 10b280e
fix: use actual magic number as ptr rather than ptr to int variable
xaviergonz e394201
fix: reinterpret cast and linting
xaviergonz af69d52
fix: better reinterpret cast
xaviergonz 927d984
fix: reverting using fixed address
xaviergonz 290b627
fix: fix for failing unit tests
xaviergonz 93d7670
Merge branch 'master' into fix-async-hooks-crash
xaviergonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis is this still undefined behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I’m reading up on the V8 code, and it seems like a real issue here is that this might actually perform an out-of-bounds read if the context has less than
dataIndex
fields…I assume the check is left out more or less intentionally on the V8 side, so I guess the options here are:
v8::Context
that tells us how many embedder data fields there areExtrasBindingObject
, then use that to tell whether an Environment has been assigned to a context or not … this might be a bit slower but wouldn’t require changes to V8/cc @nodejs/v8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @hashseed many a years ago I ran into similar trouble with the debug context and had similar thoughts to @addaleax. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
HasEmbedderData(index)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xaviergonz Do you have any thoughts on this? In the end, it’s your PR, so you obviously have some say in what happens here.
In particular, wrt the second option, that should be doable without waiting for anything else to happen, and it would be nice if you could indicate whether you’d want to try it yourself or prefer for somebody else to take a stab.
(If you do: We’d be really, really glad if we can help in any way. Don’t be shy to ask questions, here or on IRC!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat certain that
Isolate::GetCurrentContext
should give you the same context, since we run the microtask in the context of the Promise. IfObject::CreationContext
andIsolate::GetCurrentContext
returns different contexts, you got a problem anyways, sinceEnvironment::GetCurrent
uses the latter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hashseed How do we get the isolate without
Isolate::GetCurrent()
orpromise->GetIsolate()
? Both seem worse than what we have now…There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise->GetIsolate
get's it by masking off the object address to get to the heap page, where the isolate address is stored. That's not too bad.Isolate::GetCurrent
reads it from TLS, which can be slow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah about that...