File tree Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Expand file tree Collapse file tree 3 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
### Embedded Sass
4
4
5
+ * Fix a race condition where closing standard input while requests are in-flight
6
+ could sometimes cause the process to hang rather than shutting down
7
+ gracefully.
8
+
5
9
* Properly include the root stylesheet's URL in the set of loaded URLs when it
6
10
fails to parse.
7
11
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class IsolateDispatcher {
46
46
/// The actual isolate objects that have been spawned.
47
47
///
48
48
/// Only used for cleaning up the process when the underlying channel closes.
49
- final _allIsolates = < Isolate > [];
49
+ final _allIsolates = < Future < Isolate > > [];
50
50
51
51
/// A pool controlling how many isolates (and thus concurrent compilations)
52
52
/// may be live at once.
@@ -101,10 +101,10 @@ class IsolateDispatcher {
101
101
}
102
102
}, onError: (Object error, StackTrace stackTrace) {
103
103
_handleError (error, stackTrace);
104
- }, onDone: () {
104
+ }, onDone: () async {
105
105
_closed = true ;
106
106
for (var isolate in _allIsolates) {
107
- isolate.kill ();
107
+ ( await isolate) .kill ();
108
108
}
109
109
110
110
// Killing isolates isn't sufficient to make sure the process closes; we
@@ -130,7 +130,9 @@ class IsolateDispatcher {
130
130
}
131
131
132
132
var receivePort = ReceivePort ();
133
- _allIsolates.add (await Isolate .spawn (_isolateMain, receivePort.sendPort));
133
+ var future = Isolate .spawn (_isolateMain, receivePort.sendPort);
134
+ _allIsolates.add (future);
135
+ await future;
134
136
135
137
var channel = IsolateChannel <_InitialMessage ?>.connectReceive (receivePort)
136
138
.transform (const ExplicitCloseTransformer ());
Original file line number Diff line number Diff line change @@ -224,6 +224,19 @@ void main() {
224
224
await process.shouldExit (0 );
225
225
});
226
226
227
+ test ("closes gracefully with many in-flight compilations" , () async {
228
+ // This should always be equal to the size of
229
+ // [IsolateDispatcher._isolatePool], since that's as many concurrent
230
+ // compilations as we can realistically have anyway.
231
+ var totalRequests = 15 ;
232
+ for (var i = 1 ; i <= totalRequests; i++ ) {
233
+ process.inbound
234
+ .add ((i, compileString ("a {b: foo() + 2px}" , functions: [r"foo()" ])));
235
+ }
236
+
237
+ await process.close ();
238
+ }, skip: "Enable once dart-lang/stream_channel#92 is released" );
239
+
227
240
test ("doesn't include a source map by default" , () async {
228
241
process.send (compileString ("a {b: 1px + 2px}" ));
229
242
await expectSuccess (process, "a { b: 3px; }" , sourceMap: isEmpty);
You can’t perform that action at this time.
0 commit comments