diff --git a/nats/io/client.py b/nats/io/client.py index ff302da..d09c878 100644 --- a/nats/io/client.py +++ b/nats/io/client.py @@ -323,7 +323,9 @@ def connect(self, self._status = Client.CONNECTING yield self._process_connect_init() break - except (socket.error, tornado.iostream.StreamClosedError) as e: + except ErrNoServers: + raise + except Exception as e: self._status = Client.DISCONNECTED self._err = e if self._error_cb is not None: @@ -1127,7 +1129,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 +1205,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 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)