Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dart vm lockup during shutdown with pending requests #2279

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/src/embedded/compilation_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions lib/src/embedded/reusable_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading