Commit 03599e74 authored by Valentin Valls's avatar Valentin Valls
Browse files

Merge branch '2831-rpc-fail-to-disconnect-an-event-when-the-server-was-closed' into 'master'

Resolve "RPC: Fail to disconnect an event when the server was closed"

Closes #2831

See merge request !3818
parents 57774c40 40de3643
Pipeline #49053 passed with stages
in 111 minutes and 17 seconds
......@@ -613,6 +613,9 @@ class RpcConnection:
def _call__(self, code, args, kwargs, retry_on_disconnect=True):
log_debug(self, f"rpc client ({self._address}): '{code}' args={args}")
if self._socket is None:
# Check if already return a sub client
method_name = args[0] if args else ""
value = self._subclient.get((code, method_name))
......@@ -719,7 +722,7 @@ class Client(proxy.Proxy):
rpc_connection = RpcConnection(address, disconnect_callback, timeout)
object.__setattr__(self, "_rpc_connection", rpc_connection)
object.__setattr__(self, "_Client__class", None)
super().__init__(lambda: rpc_connection._proxy)
super().__init__(lambda: rpc_connection._proxy, init_once=True)
def __class__(self):
......@@ -435,3 +435,35 @@ def test_nonexisting_host(beacon):
raise CommunicationError(str(eee)) from eee
def test_disconnect_event_with_closed_server():
url = "tcp://"
results = gevent.queue.Queue()
def callback(*args):
with rpc_server(url) as (server, car):
client_car = Client(url)
event.connect(client_car, "test", callback)
event.send(car, "test", 3)
assert results.get() == (3,)
event.disconnect(client_car, "test", callback)
with rpc_server(url) as (server, car):
# Synchronize
event.send(car, "test", 4)
# the previous event should not update 'results' since
# the event is disconnected
assert len(results) == 0
# close client
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment