From 5d9c449c18f35544c9dece9a5a0f66fc62865d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=AA=E3=81=A4=E3=81=8D?= Date: Fri, 15 Nov 2024 16:34:16 -0800 Subject: [PATCH] Pass exitCode via message --- lib/src/embedded/compilation_dispatcher.dart | 5 +++-- lib/src/embedded/isolate_dispatcher.dart | 13 +++++++------ lib/src/embedded/js/reusable_isolate.dart | 9 --------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/src/embedded/compilation_dispatcher.dart b/lib/src/embedded/compilation_dispatcher.dart index 939a372a1..4f453da16 100644 --- a/lib/src/embedded/compilation_dispatcher.dart +++ b/lib/src/embedded/compilation_dispatcher.dart @@ -3,6 +3,7 @@ // https://opensource.org/licenses/MIT. import 'dart:convert'; +import 'dart:io' if (dart.library.js) 'js/io.dart'; import 'dart:isolate' if (dart.library.js) 'js/isolate.dart'; import 'dart:typed_data'; @@ -366,14 +367,14 @@ final class CompilationDispatcher { message.writeToCodedBufferWriter(protobufWriter); // Add one additional byte to the beginning to indicate whether or not the - // compilation has finished (1) or encountered a fatal error (2), so the + // compilation has finished (1) or encountered a fatal error (exitCode), so the // [IsolateDispatcher] knows whether to treat this isolate as inactive or // close out entirely. var packet = Uint8List( 1 + _compilationIdVarint.length + protobufWriter.lengthInBytes); packet[0] = switch (message.whichMessage()) { OutboundMessage_Message.compileResponse => 1, - OutboundMessage_Message.error => 2, + OutboundMessage_Message.error => exitCode, _ => 0 }; packet.setAll(1, _compilationIdVarint); diff --git a/lib/src/embedded/isolate_dispatcher.dart b/lib/src/embedded/isolate_dispatcher.dart index e4fbb2cbf..d2082f9c0 100644 --- a/lib/src/embedded/isolate_dispatcher.dart +++ b/lib/src/embedded/isolate_dispatcher.dart @@ -127,11 +127,11 @@ class IsolateDispatcher { var fullBuffer = message as Uint8List; // The first byte of messages from isolates indicates whether the entire - // compilation is finished (1) or if it encountered an error (2). Sending - // this as part of the message buffer rather than a separate message - // avoids a race condition where the host might send a new compilation - // request with the same ID as one that just finished before the - // [IsolateDispatcher] receives word that the isolate with that ID is + // compilation is finished (1) or if it encountered an error (exitCode). + // Sending this as part of the message buffer rather than a separate + // message avoids a race condition where the host might send a new + // compilation request with the same ID as one that just finished before + // the [IsolateDispatcher] receives word that the isolate with that ID is // done. See sass/dart-sass#2004. var category = fullBuffer[0]; var packet = Uint8List.sublistView(fullBuffer, 1); @@ -145,8 +145,9 @@ class IsolateDispatcher { _inactiveIsolates.add(isolate); resource.release(); _channel.sink.add(packet); - case 2: + default: _channel.sink.add(packet); + exitCode = category; if (_gracefulShutdown) { _channel.sink.close(); } else { diff --git a/lib/src/embedded/js/reusable_isolate.dart b/lib/src/embedded/js/reusable_isolate.dart index 6919d82e6..e80173c84 100644 --- a/lib/src/embedded/js/reusable_isolate.dart +++ b/lib/src/embedded/js/reusable_isolate.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'dart:js_interop'; import 'dart:typed_data'; -import 'io.dart'; import 'js.dart'; import 'sync_message_port.dart'; import 'worker_threads.dart'; @@ -46,14 +45,6 @@ class ReusableIsolate { workerData: channel.port2, transferList: [channel.port2].toJS, argv: argv)); - worker.once( - 'exit', - (int code) { - // Worker exit code 1 means it is killed by worker.terminate() - if (code > exitCode && code != 1) { - exitCode = code; - } - }.toJS); var controller = StreamController(sync: true); var sendPort = SyncMessagePort(channel.port1); var receivePort = channel.port1;