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

inspector: fix inspector hung while disconnecting #8021

Closed
wants to merge 1 commit into from
Closed

inspector: fix inspector hung while disconnecting #8021

wants to merge 1 commit into from

Conversation

alexkozy
Copy link
Member

@alexkozy alexkozy commented Aug 8, 2016

Checklist
  • make -j4 test (UNIX), or vcbuild test nosign (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

If user during stepping make some actions (e.g. stepOver native call)
that requests program break and disconnect DevTools frontend then
AgentImpl won't be disconnected until other message from frontend.

The root of issue:

  1. Inspector requests program break.
  2. User requests disconnect (e.g. refresh page with DevTools frontend).
  3. On program break V8Inspector call runMessageLoopOnPause on
    V8NodeInspector.
  4. Message loop will wait until next message from frontend.
  5. After message Agent will be disconnected.
    We need to ignore runMessageLoopOnPause on step 3 during disconnecting.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol labels Aug 8, 2016
@alexkozy
Copy link
Member Author

alexkozy commented Aug 8, 2016

/cc @eugeneo @ofrobots @dgozman

@@ -438,6 +442,7 @@ void AgentImpl::OnRemoteDataIO(inspector_socket_t* socket,
if (client_socket_ == socket) {
String16 message(TAG_DISCONNECT, sizeof(TAG_DISCONNECT) - 1);
client_socket_ = nullptr;
disconnecting_ = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems prone to race condition. Variable is read and modified on 2 threads without any synchronization.

I wonder if it would be feasable to ::DispatchMessages when entering the main loop.

@alexkozy
Copy link
Member Author

alexkozy commented Aug 8, 2016

Improved base approach. Please take another look.

@@ -286,6 +287,8 @@ class V8NodeInspector : public blink::V8Inspector {
void runMessageLoopOnPause(int context_group_id) override {
if (running_nested_loop_)
return;
if (agent_->incoming_disconnect_message_count_)
Copy link
Contributor

Choose a reason for hiding this comment

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

This access is not guarded by a mutex...

If user during stepping make some actions (e.g. stepOver native call)
that requests program break and disconnect DevTools frontend then
AgentImpl won't be disconnected until other message from frontend.

The root of issue:
1. Inspector requests program break.
2. User requests disconnect (e.g. refresh page with DevTools frontend).
3. On program break V8Inspector call runMessageLoopOnPause on
V8NodeInspector.
4. Message loop will wait until next message from frontend.
5. After message Agent will be disconnected.
We can dispatch all pending message on step 3 to solve a problem.
@alexkozy
Copy link
Member Author

alexkozy commented Aug 8, 2016

Uploaded another approach mentioned by @eugeneo in comment.

@eugeneo
Copy link
Contributor

eugeneo commented Aug 8, 2016

LGTM

@@ -288,6 +288,7 @@ class V8NodeInspector : public blink::V8Inspector {
return;
terminated_ = false;
running_nested_loop_ = true;
agent_->DispatchMessages();
Copy link
Member

Choose a reason for hiding this comment

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

Is this thread-safe? DispatchMessages() reads and writes dispatching_messages_ without holding any locks.

@eugeneo
Copy link
Contributor

eugeneo commented Aug 9, 2016

@bnoordhuis DispatchMessages is only called on the main thread (the thread where main V8 loop runs). That flag is only used in that function to prevent reentrance.

@bnoordhuis
Copy link
Member

I guess I don't understand your previous comment about thread safety then.

@alexkozy
Copy link
Member Author

In previous patches I use variable on IO thread (in ::OnRemoteIO) and on main thread (in ::DispatchMessages). IO thread can receives another disconnect message when main thread is processing previous one.

@bnoordhuis
Copy link
Member

LGTM

@ofrobots
Copy link
Contributor

@alexkozy
Copy link
Member Author

I checked test results and it looks like failed tests don't relate to this change. Could you please try to rerun CI?

@bnoordhuis
Copy link
Member

sequential/test-crypto-timing-safe-equal is known flaky and due to be reverted, see #8225.

parallel/test-fs-utimes failing on the ppcbe-ubuntu1404 buildbot is... interesting... but unlikely to be caused by this PR.

@ofrobots
Copy link
Contributor

The failures indeed look unrelated, but here's a new CI regardless: https://ci.nodejs.org/job/node-test-pull-request/3802/

ofrobots pushed a commit that referenced this pull request Aug 23, 2016
If user make some actions during (e.g. stepOver native call)
that requests program break and disconnect DevTools frontend then
AgentImpl won't be disconnected until other message from frontend.

The root of issue:
1. Inspector requests program break.
2. User requests disconnect (e.g. refresh page with DevTools frontend).
3. On program break V8Inspector call runMessageLoopOnPause on
V8NodeInspector.
4. Message loop will wait until next message from frontend.
5. After message Agent will be disconnected.
We can dispatch all pending message on step 3 to solve a problem.

PR-URL: #8021
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
@ofrobots
Copy link
Contributor

New CI had different hiccups but plinux tests did pass.

Landed as f7a23a2.

@ofrobots ofrobots closed this Aug 23, 2016
evanlucas pushed a commit that referenced this pull request Aug 24, 2016
If user make some actions during (e.g. stepOver native call)
that requests program break and disconnect DevTools frontend then
AgentImpl won't be disconnected until other message from frontend.

The root of issue:
1. Inspector requests program break.
2. User requests disconnect (e.g. refresh page with DevTools frontend).
3. On program break V8Inspector call runMessageLoopOnPause on
V8NodeInspector.
4. Message loop will wait until next message from frontend.
5. After message Agent will be disconnected.
We can dispatch all pending message on step 3 to solve a problem.

PR-URL: #8021
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
evanlucas added a commit that referenced this pull request Aug 24, 2016
Notable changes:

* **buffer**: Fix regression introduced in v6.4.0 that prevented .write() at buffer end (Anna Henningsen) #8154
* **inspector**:
  * fix inspector hang while disconnecting (Aleksei Koziatinskii) #8021
  * add support for uncaught exception (Aleksei Koziatinskii) #8043
* **meta**: add @joshgav to collaborators (Josh Gavant) #8146
* **repl**: Fix saving editor mode text in `.save` (Prince J Wesley) #8145
* ***Revert*** "**repl,util**: insert carriage returns in output" (Evan Lucas) #8143
evanlucas added a commit that referenced this pull request Aug 26, 2016
Notable changes:

* **buffer**: Fix regression introduced in v6.4.0 that prevented .write() at buffer end (Anna Henningsen) #8154
* **deps**: update V8 to 5.1.281.75 (Ali Ijaz Sheikh) #8054
* **inspector**:
  * fix inspector hang while disconnecting (Aleksei Koziatinskii) #8021
  * add support for uncaught exception (Aleksei Koziatinskii) #8043
* **repl**: Fix saving editor mode text in `.save` (Prince J Wesley) #8145
* ***Revert*** "**repl,util**: insert carriage returns in output" (Evan Lucas) #8143

PR-URL: #8253
evanlucas added a commit that referenced this pull request Aug 26, 2016
Notable changes:

* **buffer**: Fix regression introduced in v6.4.0 that prevented .write() at buffer end (Anna Henningsen) #8154
* **deps**: update V8 to 5.1.281.75 (Ali Ijaz Sheikh) #8054
* **inspector**:
  * fix inspector hang while disconnecting (Aleksei Koziatinskii) #8021
  * add support for uncaught exception (Aleksei Koziatinskii) #8043
* **repl**: Fix saving editor mode text in `.save` (Prince J Wesley) #8145
* ***Revert*** "**repl,util**: insert carriage returns in output" (Evan Lucas) #8143

PR-URL: #8253
evanlucas added a commit that referenced this pull request Aug 26, 2016
Notable changes:

* **buffer**: Fix regression introduced in v6.4.0 that prevented .write() at buffer end (Anna Henningsen) #8154
* **deps**: update V8 to 5.1.281.75 (Ali Ijaz Sheikh) #8054
* **inspector**:
  * fix inspector hang while disconnecting (Aleksei Koziatinskii) #8021
  * add support for uncaught exception (Aleksei Koziatinskii) #8043
* **repl**: Fix saving editor mode text in `.save` (Prince J Wesley) #8145
* ***Revert*** "**repl,util**: insert carriage returns in output" (Evan Lucas) #8143

PR-URL: #8253
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++. inspector Issues and PRs related to the V8 inspector protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants