From 4df24dbcc15c9b50979905e5eb8bbd3d37a06ce8 Mon Sep 17 00:00:00 2001 From: Brian Shannan Date: Sat, 23 Feb 2019 20:59:29 -0600 Subject: [PATCH 1/2] handle all exceptions on reconnect --- nats/io/client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nats/io/client.py b/nats/io/client.py index ff302da..2da8d7d 100644 --- a/nats/io/client.py +++ b/nats/io/client.py @@ -323,7 +323,7 @@ def connect(self, self._status = Client.CONNECTING yield self._process_connect_init() break - except (socket.error, tornado.iostream.StreamClosedError) as e: + except Exception as e: self._status = Client.DISCONNECTED self._err = e if self._error_cb is not None: @@ -1127,7 +1127,7 @@ def _attempt_reconnect(self): self._status = Client.DISCONNECTED yield self.close() break - except (socket.error, NatsError, tornado.iostream.StreamClosedError) as e: + except Exception as e: self._err = e if self._error_cb is not None: self._error_cb(e) @@ -1203,7 +1203,7 @@ def _select_next_server(self): yield self._server_connect(s) self._current_server = s break - except (socket.error, tornado.iostream.StreamClosedError) as e: + except Exception as e: s.last_attempt = time.time() s.reconnects += 1 From efc5716091b41322ccadfb655572e511bcad46dc Mon Sep 17 00:00:00 2001 From: Brian Shannan Date: Mon, 25 Feb 2019 18:47:06 -0600 Subject: [PATCH 2/2] fix a test --- nats/io/client.py | 2 ++ tests/client_test.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nats/io/client.py b/nats/io/client.py index 2da8d7d..d09c878 100644 --- a/nats/io/client.py +++ b/nats/io/client.py @@ -323,6 +323,8 @@ def connect(self, self._status = Client.CONNECTING yield self._process_connect_init() break + except ErrNoServers: + raise except Exception as e: self._status = Client.DISCONNECTED self._err = e diff --git a/tests/client_test.py b/tests/client_test.py index 9abf975..ba96639 100644 --- a/tests/client_test.py +++ b/tests/client_test.py @@ -1082,10 +1082,13 @@ def disconnected_cb(self): "read_chunk_size": 10, "error_cb": c.error_cb, "close_cb": c.close_cb, - "disconnected_cb": c.disconnected_cb + "disconnected_cb": c.disconnected_cb, + "max_reconnect_attempts": 1, } - with self.assertRaises(tornado.iostream.StreamBufferFullError): + with self.assertRaises(ErrNoServers): yield c.nc.connect(**options) + self.assertEqual( + tornado.iostream.StreamBufferFullError, c.nc.last_error().__class__) self.assertFalse(c.nc.is_connected) self.assertEqual(1024, c.nc._max_read_buffer_size) self.assertEqual(50, c.nc._max_write_buffer_size)