Skip to content

Commit b5889d0

Browse files
addaleaxtargos
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 1c3a2eb commit b5889d0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_worker.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void Worker::Run() {
136136
TRACE_STR_COPY(name.c_str()));
137137
MultiIsolatePlatform* platform = isolate_data_->platform();
138138
CHECK_NE(platform, nullptr);
139+
bool inspector_started = false;
139140

140141
Debug(this, "Starting worker with id %llu", thread_id_);
141142
{
@@ -163,6 +164,9 @@ void Worker::Run() {
163164
}
164165

165166
if (!is_stopped()) {
167+
StartWorkerInspector(env_.get(), url_);
168+
inspector_started = true;
169+
166170
HandleScope handle_scope(isolate_);
167171
Environment::AsyncCallbackScope callback_scope(env_.get());
168172
env_->async_hooks()->push_async_ids(1, 0);
@@ -171,7 +175,6 @@ void Worker::Run() {
171175
env_->async_hooks()->pop_async_id(1);
172176

173177
Debug(this, "Loaded environment for worker %llu", thread_id_);
174-
StartWorkerInspector(env_.get(), url_);
175178
}
176179

177180
{
@@ -232,7 +235,8 @@ void Worker::Run() {
232235
env_->stop_sub_worker_contexts();
233236
env_->RunCleanup();
234237
RunAtExit(env_.get());
235-
WaitForWorkerInspectorToStop(env_.get());
238+
if (inspector_started)
239+
WaitForWorkerInspectorToStop(env_.get());
236240

237241
{
238242
Mutex::ScopedLock stopped_lock(stopped_mutex_);

0 commit comments

Comments
 (0)