From f2e1df1997ec692e05184e62a4120799b2bf7305 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 28 Jan 2026 11:10:42 -0800 Subject: [PATCH] [vm] Avoid deadlock in Isolate.debugName. TEST=ci Bug: https://github.com/dart-lang/sdk/issues/62237 Change-Id: I57bfcc341e34aa9e873092e0f7ebf44bc2f95cfc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476143 Commit-Queue: Ryan Macnak Reviewed-by: Alexander Aprelev --- .../dart/isolates/many_debug_name_test.dart | 24 +++++++++++++++++++ runtime/vm/isolate.cc | 4 ---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 runtime/tests/vm/dart/isolates/many_debug_name_test.dart diff --git a/runtime/tests/vm/dart/isolates/many_debug_name_test.dart b/runtime/tests/vm/dart/isolates/many_debug_name_test.dart new file mode 100644 index 00000000000..ad737f43ca3 --- /dev/null +++ b/runtime/tests/vm/dart/isolates/many_debug_name_test.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:isolate'; + +child(replyPort) { + for (var i = 0; i < 10; i++) { + replyPort.send(Isolate.current.debugName); + } +} + +main() async { + var pending = 0; + var port = new RawReceivePort(); + port.handler = (_) { + pending--; + if (pending == 0) port.close(); + }; + for (var i = 0; i < 20; i++) { + pending += 10; + Isolate.spawn(child, port.sendPort); + } +} diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index 86d91f58b82..64e652b25d3 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -3617,9 +3617,6 @@ void Isolate::PauseEventHandler() { #endif // !defined(PRODUCT) void Isolate::VisitIsolates(IsolateVisitor* visitor) { - if (visitor == nullptr) { - return; - } IsolateGroup::ForEach([&](IsolateGroup* group) { group->ForEachIsolate( [&](Isolate* isolate) { visitor->VisitIsolate(isolate); }); @@ -3635,7 +3632,6 @@ intptr_t Isolate::IsolateListLength() { } std::unique_ptr Isolate::LookupIsolateNameByPort(Dart_Port port) { - MonitorLocker ml(isolate_creation_monitor_); std::unique_ptr result; IsolateGroup::ForEach([&](IsolateGroup* group) { group->ForEachIsolate([&](Isolate* isolate) {