Skip to content

Commit ac791ad

Browse files
[flutter_tools] flutter daemon handles a closed stdout IOSink (#105075)
1 parent feda45a commit ac791ad

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/flutter_tools/lib/src/daemon.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ class DaemonStreams {
219219
if (binary != null) {
220220
_outputSink.add(binary);
221221
}
222+
} on StateError catch (error) {
223+
_logger.printError('Failed to write daemon command response: $error');
224+
// Failed to send, close the connection
225+
_outputSink.close();
222226
} on IOException catch (error) {
223227
_logger.printError('Failed to write daemon command response: $error');
224228
// Failed to send, close the connection

packages/flutter_tools/test/general.shard/daemon_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ void main() {
364364
await daemonStreams.dispose();
365365
expect(outputStream.isClosed, true);
366366
});
367+
368+
testWithoutContext('handles sending to a closed sink', () async {
369+
// Unless the stream is listened to, the call to .close() will never
370+
// complete
371+
outputStream.stream.listen((List<int> _) {});
372+
await outputStream.sink.close();
373+
daemonStreams.send(testCommand);
374+
expect(
375+
bufferLogger.errorText,
376+
contains(
377+
'Failed to write daemon command response: Bad state: Cannot add event after closing',
378+
),
379+
);
380+
});
367381
});
368382
}
369383

0 commit comments

Comments
 (0)