Skip to content

Commit a5d97f0

Browse files
committed
add TODO about serializing writes
1 parent 7e24822 commit a5d97f0

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/flutter_tools/lib/src/base/process.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,11 @@ abstract class ProcessUtils {
228228

229229
/// Write [line] to [stdin] and catch any errors with [onError].
230230
///
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
233236
/// [ZoneSpecification] error handler.
234237
///
235238
/// On some platforms, the following code appears to work:
@@ -278,6 +281,9 @@ abstract class ProcessUtils {
278281
);
279282
}
280283

284+
/// See [writelnToStdinGuarded].
285+
///
286+
/// In the event that the write or flush fails, this will throw an Exception.
281287
static Future<void> writelnToStdinUnsafe({
282288
required IOSink stdin,
283289
required String line,
@@ -289,6 +295,9 @@ abstract class ProcessUtils {
289295
);
290296
}
291297

298+
/// See [writeToStdinGuarded].
299+
///
300+
/// In the event that the write or flush fails, this will throw an Exception.
292301
static Future<void> writeToStdinUnsafe({
293302
required IOSink stdin,
294303
required String content,

packages/flutter_tools/lib/src/compile.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,23 +1067,30 @@ class DefaultResidentCompiler implements ResidentCompiler {
10671067
await _writelnToServerStdinAll(<String>[line], printTrace: printTrace);
10681068
}
10691069

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);
10721076
Future<void> _writelnToServerStdinAll(List<String> lines, {
10731077
bool printTrace = false,
10741078
}) async {
10751079
final Process? server = _server;
10761080
if (server == null) {
10771081
return;
10781082
}
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+
}
10841090
}
1091+
} finally {
1092+
request.release();
10851093
}
1086-
request.release();
10871094
}
10881095
}
10891096

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy