File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed
packages/flutter_tools/lib/src Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -228,8 +228,11 @@ abstract class ProcessUtils {
228
228
229
229
/// Write [line] to [stdin] and catch any errors with [onError] .
230
230
///
231
- /// Specifically with [Process] file descriptors, an exception that is
232
- /// thrown as part of a write can be most reliably caught with a
231
+ /// Concurrent calls to this method will result in an exception due to its
232
+ /// dependence on [IOSink.flush] (see https://github.com/dart-lang/sdk/issues/25277).
233
+ ///
234
+ /// Context: specifically with [Process] file descriptors, an exception that
235
+ /// is thrown as part of a write can be most reliably caught with a
233
236
/// [ZoneSpecification] error handler.
234
237
///
235
238
/// On some platforms, the following code appears to work:
@@ -278,6 +281,9 @@ abstract class ProcessUtils {
278
281
);
279
282
}
280
283
284
+ /// See [writelnToStdinGuarded] .
285
+ ///
286
+ /// In the event that the write or flush fails, this will throw an Exception.
281
287
static Future <void > writelnToStdinUnsafe ({
282
288
required IOSink stdin,
283
289
required String line,
@@ -289,6 +295,9 @@ abstract class ProcessUtils {
289
295
);
290
296
}
291
297
298
+ /// See [writeToStdinGuarded] .
299
+ ///
300
+ /// In the event that the write or flush fails, this will throw an Exception.
292
301
static Future <void > writeToStdinUnsafe ({
293
302
required IOSink stdin,
294
303
required String content,
Original file line number Diff line number Diff line change @@ -1067,23 +1067,30 @@ class DefaultResidentCompiler implements ResidentCompiler {
1067
1067
await _writelnToServerStdinAll (< String > [line], printTrace: printTrace);
1068
1068
}
1069
1069
1070
- // TODO dont merge; explain why this is needed
1071
- final Pool _serverWritePool = Pool (1 );
1070
+ // TODO(andrewkolos): Concurrent calls to ProcessUtils.writelnToStdinUnsafe
1071
+ // against the same stdin will result in an exception. To guard against this,
1072
+ // we need to force calls to run serially. Ideally, this wouldn't be
1073
+ // necessary since we shouldn't have multiple concurrent writes to the
1074
+ // compiler process. However, we do (https://github.com/flutter/flutter/issues/152577).
1075
+ final Pool _serverStdinWritePool = Pool (1 );
1072
1076
Future <void > _writelnToServerStdinAll (List <String > lines, {
1073
1077
bool printTrace = false ,
1074
1078
}) async {
1075
1079
final Process ? server = _server;
1076
1080
if (server == null ) {
1077
1081
return ;
1078
1082
}
1079
- final PoolResource request = await _serverWritePool.request ();
1080
- for (final String line in lines) {
1081
- await ProcessUtils .writelnToStdinUnsafe (stdin: server.stdin, line: line);
1082
- if (printTrace) {
1083
- _logger.printTrace ('<- $line ' );
1083
+ final PoolResource request = await _serverStdinWritePool.request ();
1084
+ try {
1085
+ for (final String line in lines) {
1086
+ await ProcessUtils .writelnToStdinUnsafe (stdin: server.stdin, line: line);
1087
+ if (printTrace) {
1088
+ _logger.printTrace ('<- $line ' );
1089
+ }
1084
1090
}
1091
+ } finally {
1092
+ request.release ();
1085
1093
}
1086
- request.release ();
1087
1094
}
1088
1095
}
1089
1096
You can’t perform that action at this time.
0 commit comments