Skip to content

Commit 0805313

Browse files
authored
fix the fakebroker (#124)
Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
1 parent 9ce0df7 commit 0805313

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

tests/unit/fake_broker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,17 @@ def stop(self) -> None:
111111
self._thread.join(0.5)
112112

113113
def drop_connection(self) -> None:
114-
"""Close the socket abruptly, without any ``close`` performative."""
114+
"""Close the socket abruptly, without any ``close`` performative.
115+
116+
``shutdown()`` first, same as :meth:`stop`: closing a socket from one
117+
thread doesn't reliably unblock another thread of this same process
118+
blocked in ``recv()`` on it (``_run`` sits in exactly that state) —
119+
Linux defers the actual teardown, and thus EOF on the peer, until
120+
that blocking call returns on its own, which macOS does not.
121+
"""
115122
self._stop.set()
123+
with contextlib.suppress(OSError):
124+
self._sock.shutdown(socket.SHUT_RDWR)
116125
self._sock.close()
117126

118127
# --- writing --------------------------------------------------------

0 commit comments

Comments
 (0)