Skip to content

Commit

Permalink
Pass exitCode via message
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Nov 16, 2024
1 parent 98b6ff2 commit 2fff2e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
9 changes: 5 additions & 4 deletions lib/src/embedded/compilation_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
// [IsolateDispatcher] knows whether to treat this isolate as inactive or
// close out entirely.
// 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);
Expand Down
13 changes: 7 additions & 6 deletions lib/src/embedded/isolate_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions lib/src/embedded/js/reusable_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<dynamic>(sync: true);
var sendPort = SyncMessagePort(channel.port1);
var receivePort = channel.port1;
Expand Down

0 comments on commit 2fff2e7

Please sign in to comment.