Repository navigation
src: use env’s instead of isolate’s RequestInterrupt() + v8::Platform #32523
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
Changes from 1 commit
171409a
4de323c
23b2da6
62889df
d9689db
aeb354d
7e75cc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Environment::interrupt_data_ atomic
Otherwise this potentially leads to race conditions when used in a multi-threaded environment (i.e. when used for its very purpose).
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -394,7 +394,8 @@ Environment::Environment(IsolateData* isolate_data, | |
| } | ||
|
|
||
| Environment::~Environment() { | ||
| if (interrupt_data_ != nullptr) *interrupt_data_ = nullptr; | ||
| if (Environment** interrupt_data = interrupt_data_.load()) | ||
| *interrupt_data = nullptr; | ||
|
|
||
| // FreeEnvironment() should have set this. | ||
| CHECK(is_stopping()); | ||
|
|
@@ -735,12 +736,15 @@ void Environment::RunAndClearNativeImmediates(bool only_refed) { | |
| } | ||
|
|
||
| void Environment::RequestInterruptFromV8() { | ||
| if (interrupt_data_ != nullptr) return; // Already scheduled. | ||
|
|
||
| // The Isolate may outlive the Environment, so some logic to handle the | ||
| // situation in which the Environment is destroyed before the handler runs | ||
| // is required. | ||
| interrupt_data_ = new Environment*(this); | ||
| Environment** interrupt_data = new Environment*(this); | ||
| Environment** dummy = nullptr; | ||
| if (!interrupt_data_.compare_exchange_strong(dummy, interrupt_data)) { | ||
| delete interrupt_data; | ||
| return; // Already scheduled. | ||
| } | ||
|
|
||
| isolate()->RequestInterrupt([](Isolate* isolate, void* data) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember if this callback runs asynchronously. Any chance we could get a situation where we request the interrupt here but don't run it before the Isolate is deleted? If that's possible, we would have a leak on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right – that is a possibility, but I don’t quite know what to do about it (without changing V8 APIs). The leak was already there before, too, and it’s limited to the size of a pointer…
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I have an idea. Let me see. :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. If ASAN starts to complain, we can force it to ignore this pointer (for now ASAN is happy, so we can leave it as is).
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmarchini 7e75cc1 should address this by flushing interrupts when freeing the Environment instance … feels a bit like a hack to me but I think it’s the best we can do :) |
||
| std::unique_ptr<Environment*> env_ptr { static_cast<Environment**>(data) }; | ||
|
|
@@ -751,9 +755,9 @@ void Environment::RequestInterruptFromV8() { | |
| // handled during cleanup. | ||
| return; | ||
| } | ||
| env->interrupt_data_ = nullptr; | ||
| env->interrupt_data_.store(nullptr); | ||
| env->RunAndClearInterrupts(); | ||
| }, interrupt_data_); | ||
| }, interrupt_data); | ||
| } | ||
|
|
||
| void Environment::ScheduleTimer(int64_t duration_ms) { | ||
|
|
||
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.
Maybe it's worth adding a comment here explaining what this code does.
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.
@mmarchini Done, PTAL :)