Skip to content

Commit 9aeefc9

Browse files
ntkmenex3
andauthored
Fix dart vm lockup during shutdown with pending requests (#2279)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent 8541f80 commit 9aeefc9

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
intended. Now users can run `npx sass` for local installs or just `sass` when
99
`sass-embedded` is installed globally.
1010

11+
* Fix an edge case where the Dart VM could hang when shutting down when requests
12+
were in flight.
13+
1114
## 1.77.8
1215

1316
* No user-visible changes.

lib/src/embedded/compilation_dispatcher.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ final class CompilationDispatcher {
6464
/// Listens for incoming `CompileRequests` and runs their compilations.
6565
void listen() {
6666
do {
67-
var packet = _mailbox.take();
68-
if (packet.isEmpty) break;
67+
Uint8List packet;
68+
try {
69+
packet = _mailbox.take();
70+
} on StateError catch (_) {
71+
break;
72+
}
6973

7074
try {
7175
var (compilationId, messageBuffer) = parsePacket(packet);
@@ -322,12 +326,14 @@ final class CompilationDispatcher {
322326
message.id = _outboundRequestId;
323327
_send(message);
324328

325-
var packet = _mailbox.take();
326-
if (packet.isEmpty) {
329+
Uint8List packet;
330+
try {
331+
packet = _mailbox.take();
332+
} on StateError catch (_) {
327333
// Compiler is shutting down, throw without calling `_handleError` as we
328334
// don't want to report this as an actual error.
329335
_requestError = true;
330-
throw StateError('Compiler is shutting down.');
336+
rethrow;
331337
}
332338

333339
try {

lib/src/embedded/reusable_isolate.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,8 @@ class ReusableIsolate {
122122
_receivePort.close();
123123

124124
// If the isolate is blocking on [Mailbox.take], it won't even process a
125-
// kill event, so we send an empty message to make sure it wakes up.
126-
try {
127-
_mailbox.put(Uint8List(0));
128-
} on StateError catch (_) {}
125+
// kill event, so we closed the mailbox to nofity and wake it up.
126+
_mailbox.close();
129127
}
130128
}
131129

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
http: "^1.1.0"
2121
js: ^0.6.3
2222
meta: ^1.3.0
23-
native_synchronization: ^0.2.0
23+
native_synchronization: ^0.3.0
2424
node_interop: ^2.1.0
2525
package_config: ^2.0.0
2626
path: ^1.8.0

0 commit comments

Comments
 (0)