Skip to content

Commit 1df6c06

Browse files
committed
Pass exitCode via message
1 parent 496cb02 commit 1df6c06

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

lib/src/embedded/compilation_dispatcher.dart

Lines changed: 6 additions & 5 deletions
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

@@ -408,16 +409,16 @@ final class CompilationDispatcher {
408409
message.writeToCodedBufferWriter(protobufWriter);
409410

410411
// Add one additional byte to the beginning to indicate whether or not the
411-
// compilation has finished (1) or encountered a fatal error (2), so the
412-
// [IsolateDispatcher] knows whether to treat this isolate as inactive or
413-
// close out entirely.
412+
// compilation has finished (1) or encountered a fatal error (exitCode), so
413+
// the [IsolateDispatcher] knows whether to treat this isolate as inactive
414+
// or close out entirely.
414415
var packet = Uint8List(
415416
1 + _compilationIdVarint.length + protobufWriter.lengthInBytes,
416417
);
417418
packet[0] = switch (message.whichMessage()) {
418419
OutboundMessage_Message.compileResponse => 1,
419-
OutboundMessage_Message.error => 2,
420-
_ => 0,
420+
OutboundMessage_Message.error => exitCode,
421+
_ => 0
421422
};
422423
packet.setAll(1, _compilationIdVarint);
423424
protobufWriter.writeTo(packet, 1 + _compilationIdVarint.length);

lib/src/embedded/isolate_dispatcher.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ class IsolateDispatcher {
141141
var fullBuffer = message as Uint8List;
142142

143143
// The first byte of messages from isolates indicates whether the entire
144-
// compilation is finished (1) or if it encountered an error (2). Sending
145-
// this as part of the message buffer rather than a separate message
146-
// avoids a race condition where the host might send a new compilation
147-
// request with the same ID as one that just finished before the
148-
// [IsolateDispatcher] receives word that the isolate with that ID is
144+
// compilation is finished (1) or if it encountered an error (exitCode).
145+
// Sending this as part of the message buffer rather than a separate
146+
// message avoids a race condition where the host might send a new
147+
// compilation request with the same ID as one that just finished before
148+
// the [IsolateDispatcher] receives word that the isolate with that ID is
149149
// done. See sass/dart-sass#2004.
150150
var category = fullBuffer[0];
151151
var packet = Uint8List.sublistView(fullBuffer, 1);
@@ -159,8 +159,9 @@ class IsolateDispatcher {
159159
_inactiveIsolates.add(isolate);
160160
resource.release();
161161
_channel.sink.add(packet);
162-
case 2:
162+
default:
163163
_channel.sink.add(packet);
164+
exitCode = category;
164165
if (_gracefulShutdown) {
165166
_channel.sink.close();
166167
} else {

lib/src/embedded/js/reusable_isolate.dart

Lines changed: 0 additions & 9 deletions
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)