Skip to content

Commit

Permalink
[flutter_tools] flutter daemon handles a closed stdout IOSink (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherfujino authored and camsim99 committed Aug 10, 2022
1 parent e0cc609 commit 5f99783
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class DaemonStreams {
if (binary != null) {
_outputSink.add(binary);
}
} on StateError catch (error) {
_logger.printError('Failed to write daemon command response: $error');
// Failed to send, close the connection
_outputSink.close();
} on IOException catch (error) {
_logger.printError('Failed to write daemon command response: $error');
// Failed to send, close the connection
Expand Down
14 changes: 14 additions & 0 deletions packages/flutter_tools/test/general.shard/daemon_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,20 @@ void main() {
await daemonStreams.dispose();
expect(outputStream.isClosed, true);
});

testWithoutContext('handles sending to a closed sink', () async {
// Unless the stream is listened to, the call to .close() will never
// complete
outputStream.stream.listen((List<int> _) {});
await outputStream.sink.close();
daemonStreams.send(testCommand);
expect(
bufferLogger.errorText,
contains(
'Failed to write daemon command response: Bad state: Cannot add event after closing',
),
);
});
});
}

Expand Down

0 comments on commit 5f99783

Please sign in to comment.