Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pynats/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ def _readline(self, *, size: int = None) -> bytes:
line = cast(bytes, self._socket_file.readline())
read.write(line)

if len(line) == 0:
raise ConnectionResetError(self)

if size is not None:
if read.tell() == size + len(_CRLF_):
break
Expand Down
12 changes: 12 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,15 @@ def test_request_timeout(nats_url):
with NATSClient(nats_url, socket_timeout=2) as client:
with pytest.raises(socket.timeout):
client.request("test-subject")


def test_exception_on_disconnect(nats_url):
with NATSClient(nats_url, socket_timeout=2) as client:
client.subscribe(
"test-subject", callback=lambda x: x, queue="test-queue", max_messages=2
)

client._socket_file.readline = lambda: b""

with pytest.raises(ConnectionResetError):
client.wait()