From 831f5d8cfb4eaf9a128b41aa7b713b72278f4944 Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Fri, 2 Oct 2020 22:22:33 +0200 Subject: [PATCH] Revert "Not to fail pending requests, just reschedule it (#303)" (#366) This reverts commit 9ed03b6b969b9171d5b218e0ac308ae127c56984. This change prevents client from gracefully handling connection issues and instead just makes it infinitely trying to reconnect. Closes #339 --- lib/src/client/http2_connection.dart | 3 ++- test/client_tests/client_test.dart | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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 = [];