Skip to content

Commit 1cb26f3

Browse files
committed
Pass exitCode via message and eagerly exit
1 parent 98b6ff2 commit 1cb26f3

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

lib/src/embedded/compilation_dispatcher.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://opensource.org/licenses/MIT.
44

55
import 'dart:convert';
6+
import 'dart:io' if (dart.library.js) 'js/io.dart';
67
import 'dart:isolate' if (dart.library.js) 'js/isolate.dart';
78
import 'dart:typed_data';
89

@@ -366,14 +367,14 @@ final class CompilationDispatcher {
366367
message.writeToCodedBufferWriter(protobufWriter);
367368

368369
// Add one additional byte to the beginning to indicate whether or not the
369-
// compilation has finished (1) or encountered a fatal error (2), so the
370+
// compilation has finished (1) or encountered a fatal error (exitCode), so the
370371
// [IsolateDispatcher] knows whether to treat this isolate as inactive or
371372
// close out entirely.
372373
var packet = Uint8List(
373374
1 + _compilationIdVarint.length + protobufWriter.lengthInBytes);
374375
packet[0] = switch (message.whichMessage()) {
375376
OutboundMessage_Message.compileResponse => 1,
376-
OutboundMessage_Message.error => 2,
377+
OutboundMessage_Message.error => exitCode,
377378
_ => 0
378379
};
379380
packet.setAll(1, _compilationIdVarint);

lib/src/embedded/isolate_dispatcher.dart

+7-6
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ class IsolateDispatcher {
127127
var fullBuffer = message as Uint8List;
128128

129129
// The first byte of messages from isolates indicates whether the entire
130-
// compilation is finished (1) or if it encountered an error (2). Sending
131-
// this as part of the message buffer rather than a separate message
132-
// avoids a race condition where the host might send a new compilation
133-
// request with the same ID as one that just finished before the
134-
// [IsolateDispatcher] receives word that the isolate with that ID is
130+
// compilation is finished (1) or if it encountered an error (exitCode).
131+
// Sending this as part of the message buffer rather than a separate
132+
// message avoids a race condition where the host might send a new
133+
// compilation request with the same ID as one that just finished before
134+
// the [IsolateDispatcher] receives word that the isolate with that ID is
135135
// done. See sass/dart-sass#2004.
136136
var category = fullBuffer[0];
137137
var packet = Uint8List.sublistView(fullBuffer, 1);
@@ -145,8 +145,9 @@ class IsolateDispatcher {
145145
_inactiveIsolates.add(isolate);
146146
resource.release();
147147
_channel.sink.add(packet);
148-
case 2:
148+
default:
149149
_channel.sink.add(packet);
150+
exitCode = category;
150151
if (_gracefulShutdown) {
151152
_channel.sink.close();
152153
} else {

lib/src/embedded/js/reusable_isolate.dart

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:async';
66
import 'dart:js_interop';
77
import 'dart:typed_data';
88

9-
import 'io.dart';
109
import 'js.dart';
1110
import 'sync_message_port.dart';
1211
import 'worker_threads.dart';
@@ -46,14 +45,6 @@ class ReusableIsolate {
4645
workerData: channel.port2,
4746
transferList: [channel.port2].toJS,
4847
argv: argv));
49-
worker.once(
50-
'exit',
51-
(int code) {
52-
// Worker exit code 1 means it is killed by worker.terminate()
53-
if (code > exitCode && code != 1) {
54-
exitCode = code;
55-
}
56-
}.toJS);
5748
var controller = StreamController<dynamic>(sync: true);
5849
var sendPort = SyncMessagePort(channel.port1);
5950
var receivePort = channel.port1;

0 commit comments

Comments
 (0)