Skip to content

Commit

Permalink
avoid hitting the ready completer twice
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Nov 22, 2023
1 parent 054af53 commit 9c985ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class HtmlWebSocketChannel extends StreamChannelMixin
// Unfortunately, the underlying WebSocket API doesn't expose any
// specific information about the error itself.
final error = WebSocketChannelException('WebSocket connection failed.');
_readyCompleter.completeError(error);
if (!_readyCompleter.isCompleted) {
_readyCompleter.completeError(error);
}
_controller.local.sink.addError(error);
_controller.local.sink.close();
});
Expand Down
9 changes: 8 additions & 1 deletion test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ void main() {
webSocket.close();

final channel = HtmlWebSocketChannel(webSocket);
expect(channel.ready, throwsA(isA<WebSocketChannelException>()));
await expectLater(
channel.ready,
throwsA(
isA<WebSocketChannelException>()
.having((p0) => p0.message, 'message', 'WebSocket state error: 2')
.having((p0) => p0.inner, 'inner', isNull),
),
);
});

test('.connect defaults to binary lists', () async {
Expand Down

0 comments on commit 9c985ce

Please sign in to comment.