diff --git a/lib/src/client/http2_connection.dart b/lib/src/client/http2_connection.dart index 5494f0b..235419a 100644 --- a/lib/src/client/http2_connection.dart +++ b/lib/src/client/http2_connection.dart @@ -264,8 +264,9 @@ class Http2ClientConnection implements connection.ClientConnection { } // TODO(jakobr): Log error. _cancelTimer(); + _pendingCalls.forEach((call) => _failCall(call, error)); + _pendingCalls.clear(); _setState(ConnectionState.idle); - _connect(); } void _handleReconnect() { diff --git a/test/client_tests/client_test.dart b/test/client_tests/client_test.dart index ca22de7..a8f192b 100644 --- a/test/client_tests/client_test.dart +++ b/test/client_tests/client_test.dart @@ -368,6 +368,24 @@ void main() { ); } + test('Connection errors are reported', () async { + final connectionStates = []; + harness.connection.connectionError = 'Connection error'; + harness.connection.onStateChanged = (connection) { + final state = connection.state; + connectionStates.add(state); + }; + + final expectedException = + GrpcError.unavailable('Error connecting: Connection error'); + + await harness.expectThrows( + harness.client.unary(dummyValue), expectedException); + + expect( + connectionStates, [ConnectionState.connecting, ConnectionState.idle]); + }); + test('Connections time out if idle', () async { final done = Completer(); final connectionStates = [];