Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix if-else for send_recv_from_rpc #8809

Merged
merged 1 commit into from
Aug 1, 2024
Merged
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
4 changes: 2 additions & 2 deletions distributed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,11 @@ async def send_recv_from_rpc(**kwargs):
except (RPCClosed, CommClosedError) as e:
if comm:
raise type(e)(
f"Exception while trying to call remote method {key!r} before comm was established."
f"Exception while trying to call remote method {key!r} using comm {comm!r}."
) from e
else:
raise type(e)(
f"Exception while trying to call remote method {key!r} using comm {comm!r}."
f"Exception while trying to call remote method {key!r} before comm was established."
) from e

self.comms[comm] = True # mark as open
Expand Down
15 changes: 15 additions & 0 deletions distributed/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from distributed.comm.tcp import TCPBackend, TCPListener
from distributed.core import (
ConnectionPool,
RPCClosed,
Server,
Status,
_expects_comm,
Expand Down Expand Up @@ -923,6 +924,20 @@ async def test_rpc_serialization():
assert result == {"result": inc}


@gen_test()
async def test_rpc_closed_exception():
async with Server({"echo": echo_serialize}) as server:
await server.listen("tcp://")

async with rpc(server.address, serializers=["msgpack"]) as r:
r.status = Status.closed
with pytest.raises(
RPCClosed,
match="Exception while trying to call remote method .* before comm was established.",
):
await r.__getattr__("foo")()


@gen_cluster()
async def test_thread_id(s, a, b):
assert s.thread_id == a.thread_id == b.thread_id == threading.get_ident()
Expand Down
Loading