diff --git a/pilotprotocol/client.py b/pilotprotocol/client.py index 2a52cf0..bc0caa9 100644 --- a/pilotprotocol/client.py +++ b/pilotprotocol/client.py @@ -1058,7 +1058,7 @@ def read_event(conn): else: yield (event_topic, event_data) except Exception as e: - if "connection closed" in str(e).lower() or "EOF" in str(e): + if isinstance(e, PilotError) and "connection closed" in str(e).lower(): break raise finally: diff --git a/tests/test_services.py b/tests/test_services.py index 02457d7..3f67de6 100644 --- a/tests/test_services.py +++ b/tests/test_services.py @@ -406,15 +406,18 @@ def read(self, size: int = 4096) -> bytes: assert events == [] assert conn.closed is True - def test_eof_error_breaks_cleanly(self, monkeypatch): + def test_eof_error_propagates(self, monkeypatch): + # RuntimeError containing "EOF" is NOT a clean disconnect — + # only PilotError("connection closed") should be silenced. class EofConn(FakeConn): def read(self, size: int = 4096) -> bytes: raise RuntimeError("unexpected EOF on stream") conn = EofConn() d = _make_driver_with_dial(monkeypatch, conn) - events = list(d.subscribe_event("0:0001.0000.0002", "t", timeout=2)) - assert events == [] + with pytest.raises(RuntimeError, match="unexpected EOF on stream"): + list(d.subscribe_event("0:0001.0000.0002", "t", timeout=2)) + assert conn.closed is True def test_other_exception_propagates(self, monkeypatch): # Error string contains neither "connection closed" nor "EOF" —