Skip to content

Commit

Permalink
Merge pull request #64 from brianshannan/reconnect_exceptions
Browse files Browse the repository at this point in the history
handle all exceptions on reconnect
  • Loading branch information
wallyqs authored Feb 26, 2019
2 parents ac5b0dd + efc5716 commit a87e30a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions nats/io/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a87e30a

Please sign in to comment.