Skip to content

Commit

Permalink
fix: ensure we wait for the inspect to disconnect
Browse files Browse the repository at this point in the history
This re-orders our node clean up so that we free the environment before
the task runner is cleaned up as node uses the task runner during clean
up.  It also calls WaitForDisconnect() to ensure that inspector agents
are notified that the context is going down.
  • Loading branch information
MarshallOfSound committed Jul 24, 2019
1 parent 60821c8 commit 2132fdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 6 additions & 3 deletions shell/app/node_main.cc
Expand Up @@ -113,12 +113,15 @@ int NodeMain(int argc, char* argv[]) {

node_debugger.Stop();
exit_code = node::EmitExit(env);
env->set_can_call_into_js(false);
node::RunAtExit(env);
gin_env.platform()->DrainTasks(env->isolate());
gin_env.platform()->CancelPendingDelayedTasks(env->isolate());
gin_env.platform()->UnregisterIsolate(env->isolate());

v8::Isolate* isolate = env->isolate();
node::FreeEnvironment(env);

gin_env.platform()->DrainTasks(isolate);
gin_env.platform()->CancelPendingDelayedTasks(isolate);
gin_env.platform()->UnregisterIsolate(isolate);
}

// According to "src/gin/shell/gin_main.cc":
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/node_debugger.cc
Expand Up @@ -60,8 +60,10 @@ void NodeDebugger::Start() {

void NodeDebugger::Stop() {
auto* inspector = env_->inspector_agent();
if (inspector && inspector->IsListening())
if (inspector && inspector->IsListening()) {
inspector->WaitForDisconnect();
inspector->Stop();
}
}

} // namespace electron
1 change: 1 addition & 0 deletions spec/node-spec.js
Expand Up @@ -390,6 +390,7 @@ describe('node feature', () => {
const connection = new WebSocket(socketMatch[0])
connection.onopen = () => {
child.send('plz-quit')
connection.close()
done()
}
}
Expand Down

0 comments on commit 2132fdf

Please sign in to comment.