-
Notifications
You must be signed in to change notification settings - Fork 30k
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: limit foreground tasks draining loop #19987
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
66a7421
src: limit foreground tasks draining loop
ulan 4dbc4aa
[squash] clarify the comment of flushing
ulan c435401
[squash] fix the repost count in the new test.
ulan 167ae0e
[squash] drain all tasks in inspector-agent.
ulan f46763b
[squash] fix comment s/iff/if/.
ulan 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "node_internals.h" | ||
#include "libplatform/libplatform.h" | ||
|
||
#include <string> | ||
#include "gtest/gtest.h" | ||
#include "node_test_fixture.h" | ||
|
||
// This task increments the given run counter and reposts itself until the | ||
// repost counter reaches zero. | ||
class RepostingTask : public v8::Task { | ||
public: | ||
explicit RepostingTask(int repost_count, | ||
int* run_count, | ||
v8::Isolate* isolate, | ||
node::NodePlatform* platform) | ||
: repost_count_(repost_count), | ||
run_count_(run_count), | ||
isolate_(isolate), | ||
platform_(platform) {} | ||
|
||
// v8::Task implementation | ||
void Run() final { | ||
++*run_count_; | ||
if (repost_count_ > 0) { | ||
--repost_count_; | ||
platform_->CallOnForegroundThread(isolate_, | ||
new RepostingTask(repost_count_, run_count_, isolate_, platform_)); | ||
} | ||
} | ||
|
||
private: | ||
int repost_count_; | ||
int* run_count_; | ||
v8::Isolate* isolate_; | ||
node::NodePlatform* platform_; | ||
}; | ||
|
||
class PlatformTest : public EnvironmentTestFixture {}; | ||
|
||
TEST_F(PlatformTest, SkipNewTasksInFlushForegroundTasks) { | ||
v8::Isolate::Scope isolate_scope(isolate_); | ||
const v8::HandleScope handle_scope(isolate_); | ||
const Argv argv; | ||
Env env {handle_scope, argv}; | ||
int run_count = 0; | ||
platform->CallOnForegroundThread( | ||
isolate_, new RepostingTask(2, &run_count, isolate_, platform.get())); | ||
EXPECT_TRUE(platform->FlushForegroundTasks(isolate_)); | ||
EXPECT_EQ(1, run_count); | ||
EXPECT_TRUE(platform->FlushForegroundTasks(isolate_)); | ||
EXPECT_EQ(2, run_count); | ||
EXPECT_TRUE(platform->FlushForegroundTasks(isolate_)); | ||
EXPECT_EQ(3, run_count); | ||
EXPECT_FALSE(platform->FlushForegroundTasks(isolate_)); | ||
} |
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.
Doesn't this line preserve the bug? Because, even though you swap the queue before draining it, you're still running this loop forever if new tasks are constantly added to the original queue
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.
The inspector posts foreground tasks and requires that they are all processed before going to the outer loop.
AFAIK this code runs only when the inspector is active and the program is paused. The normal libuv tasks are not processed here. Latency shouldn't be an issue.
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.
My understanding is that the original bug this is trying to fix (#19937) is that there are cases where foreground tasks can add additional tasks to the queue. The bug was fixed by freezing the queue inside of FlushForegroundTasks, but this line of code I'm commenting on appears to loop THAT CALL so that the freeze fix doesn't actually help anything. It still will run forever, if foreground tasks add themselves.
Unless there's more than one place where
FlushForegroundTasks
is being called, and that's not an issue for this line?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 is certainly more than one place. This particular line addresses a very specific interaction.