@@ -142,14 +142,14 @@ class WorkerDispatcher {
142
142
var fullBuffer = message as Uint8List ;
143
143
144
144
// The first byte of messages from workers indicates whether the entire
145
- // compilation is finished (1) or if it encountered an error (exitCode ).
145
+ // compilation is finished (1) or if it encountered an error (2 ).
146
146
// Sending this as part of the message buffer rather than a separate
147
147
// message avoids a race condition where the host might send a new
148
148
// compilation request with the same ID as one that just finished before
149
149
// the [WorkerDispatcher] receives word that the worker with that ID is
150
150
// done. See sass/dart-sass#2004.
151
151
var category = fullBuffer[0 ];
152
- var packet = Uint8List .sublistView (fullBuffer, 1 );
152
+ var packet = Uint8List .sublistView (fullBuffer, 2 );
153
153
154
154
switch (category) {
155
155
case 0 :
@@ -160,9 +160,18 @@ class WorkerDispatcher {
160
160
_inactiveWorkers.add (worker);
161
161
resource.release ();
162
162
_channel.sink.add (packet);
163
- default :
163
+ case 2 :
164
164
_channel.sink.add (packet);
165
- exitCode = category;
165
+ // The second byte of message is the exitCode when fatal error
166
+ // occurs. This is needed because in Node.js process.exitCode
167
+ // is thread local, so that we need to pass it from the worker
168
+ // thread back to main thread. Using onexit event to retrieve
169
+ // the exitCode is unrelibale because worker.kill() might get
170
+ // triggered from main thread before the worker thread finish
171
+ // exit itself, in which case onexit event will recevie an exit
172
+ // code 1 regardless of actual process.exitCode value in worker
173
+ // thread.
174
+ exitCode = fullBuffer[1 ];
166
175
if (_gracefulShutdown) {
167
176
_channel.sink.close ();
168
177
} else {
0 commit comments