From 2e25712481c2f631660621bbe674b67b20d8bf34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Thu, 11 Jul 2024 12:01:42 -0700 Subject: [PATCH 1/2] Fix dart vm lockup during shutdown with pending requests --- lib/src/embedded/compilation_dispatcher.dart | 16 +++++++++++----- lib/src/embedded/reusable_isolate.dart | 6 ++---- pubspec.yaml | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/src/embedded/compilation_dispatcher.dart b/lib/src/embedded/compilation_dispatcher.dart index e8c3764b5..8f69b2553 100644 --- a/lib/src/embedded/compilation_dispatcher.dart +++ b/lib/src/embedded/compilation_dispatcher.dart @@ -64,8 +64,12 @@ final class CompilationDispatcher { /// Listens for incoming `CompileRequests` and runs their compilations. void listen() { do { - var packet = _mailbox.take(); - if (packet.isEmpty) break; + Uint8List packet; + try { + packet = _mailbox.take(); + } on StateError catch (_) { + break; + } try { var (compilationId, messageBuffer) = parsePacket(packet); @@ -322,12 +326,14 @@ final class CompilationDispatcher { message.id = _outboundRequestId; _send(message); - var packet = _mailbox.take(); - if (packet.isEmpty) { + Uint8List packet; + try { + packet = _mailbox.take(); + } on StateError catch (_) { // Compiler is shutting down, throw without calling `_handleError` as we // don't want to report this as an actual error. _requestError = true; - throw StateError('Compiler is shutting down.'); + rethrow; } try { diff --git a/lib/src/embedded/reusable_isolate.dart b/lib/src/embedded/reusable_isolate.dart index 0ed9eec8c..5cdd6bbd8 100644 --- a/lib/src/embedded/reusable_isolate.dart +++ b/lib/src/embedded/reusable_isolate.dart @@ -122,10 +122,8 @@ class ReusableIsolate { _receivePort.close(); // If the isolate is blocking on [Mailbox.take], it won't even process a - // kill event, so we send an empty message to make sure it wakes up. - try { - _mailbox.put(Uint8List(0)); - } on StateError catch (_) {} + // kill event, so we closed the mailbox to nofity and wake it up. + _mailbox.close(); } } diff --git a/pubspec.yaml b/pubspec.yaml index 1c78769ae..d0b4550e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,7 +20,7 @@ dependencies: http: "^1.1.0" js: ^0.6.3 meta: ^1.3.0 - native_synchronization: ^0.2.0 + native_synchronization: ^0.3.0 node_interop: ^2.1.0 package_config: ^2.0.0 path: ^1.8.0 From 31c624eb4fde33fb2573905eb18247d760e1d621 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 1 Aug 2024 11:44:01 -0700 Subject: [PATCH 2/2] Update pubspec/changelog --- CHANGELOG.md | 7 +++++++ pkg/sass_api/CHANGELOG.md | 4 ++++ pkg/sass_api/pubspec.yaml | 4 ++-- pubspec.yaml | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8533ae1c8..65a295d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.78.0 + +### Embedded Sass + +* Fix an edge case where the Dart VM could hang when shutting down when requests + were in flight. + ## 1.77.8 * No user-visible changes. diff --git a/pkg/sass_api/CHANGELOG.md b/pkg/sass_api/CHANGELOG.md index 7753afacf..cbedd7005 100644 --- a/pkg/sass_api/CHANGELOG.md +++ b/pkg/sass_api/CHANGELOG.md @@ -1,3 +1,7 @@ +## 10.5.0 + +* No user-visible changes. + ## 10.4.8 * No user-visible changes. diff --git a/pkg/sass_api/pubspec.yaml b/pkg/sass_api/pubspec.yaml index 565bb7d8d..5b106ec6f 100644 --- a/pkg/sass_api/pubspec.yaml +++ b/pkg/sass_api/pubspec.yaml @@ -2,7 +2,7 @@ name: sass_api # Note: Every time we add a new Sass AST node, we need to bump the *major* # version because it's a breaking change for anyone who's implementing the # visitor interface(s). -version: 10.4.8 +version: 10.5.0-dev description: Additional APIs for Dart Sass. homepage: https://github.com/sass/dart-sass @@ -10,7 +10,7 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - sass: 1.77.8 + sass: 1.78.0-dev dev_dependencies: dartdoc: ">=6.0.0 <9.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index d0b4550e2..bb851e64e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.77.8 +version: 1.78.0-dev description: A Sass implementation in Dart. homepage: https://github.com/sass/dart-sass