Skip to content

Commit e6d0ced

Browse files
addaleaxTrott
authored andcommitted
worker: only stop inspector if started
This may fix some flakiness with tests that use `worker.terminate()`. In particular, the following failure seems like it could be related (no consistent reproduction available, though): ``` 15:30:14 not ok 187 parallel/test-heapdump-worker 15:30:14 --- 15:30:14 duration_ms: 2.499 15:30:14 severity: fail 15:30:14 exitcode: 134 15:30:14 stack: |- 15:30:14 npm[6904]: src\inspector_agent.cc:729: Assertion `(client_) != nullptr' failed. ``` From https://ci.nodejs.org/job/node-test-binary-windows/20041/COMPILED_BY=vs2017,RUNNER=win2016,RUN_SUBSET=2/console Refs: #22769 PR-URL: #22927 Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]>
1 parent a7b59d6 commit e6d0ced

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_worker.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ void Worker::Run() {
150150
TRACE_STR_COPY(name.c_str()));
151151
MultiIsolatePlatform* platform = isolate_data_->platform();
152152
CHECK_NE(platform, nullptr);
153+
bool inspector_started = false;
153154

154155
Debug(this, "Starting worker with id %llu", thread_id_);
155156
{
@@ -177,6 +178,9 @@ void Worker::Run() {
177178
}
178179

179180
if (!is_stopped()) {
181+
StartWorkerInspector(env_.get(), url_);
182+
inspector_started = true;
183+
180184
HandleScope handle_scope(isolate_);
181185
Environment::AsyncCallbackScope callback_scope(env_.get());
182186
env_->async_hooks()->push_async_ids(1, 0);
@@ -185,7 +189,6 @@ void Worker::Run() {
185189
env_->async_hooks()->pop_async_id(1);
186190

187191
Debug(this, "Loaded environment for worker %llu", thread_id_);
188-
StartWorkerInspector(env_.get(), url_);
189192
}
190193

191194
{
@@ -246,7 +249,8 @@ void Worker::Run() {
246249
env_->stop_sub_worker_contexts();
247250
env_->RunCleanup();
248251
RunAtExit(env_.get());
249-
WaitForWorkerInspectorToStop(env_.get());
252+
if (inspector_started)
253+
WaitForWorkerInspectorToStop(env_.get());
250254

251255
{
252256
Mutex::ScopedLock stopped_lock(stopped_mutex_);

0 commit comments

Comments
 (0)