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: ...@@ -613,6 +613,9 @@ class RpcConnection:
def _call__(self, code, args, kwargs, retry_on_disconnect=True): def _call__(self, code, args, kwargs, retry_on_disconnect=True):
log_debug(self, f"rpc client ({self._address}): '{code}' args={args}") log_debug(self, f"rpc client ({self._address}): '{code}' args={args}")
if self._socket is None:
self.connect()
# Check if already return a sub client # Check if already return a sub client
method_name = args[0] if args else "" method_name = args[0] if args else ""
value = self._subclient.get((code, method_name)) value = self._subclient.get((code, method_name))
...@@ -719,7 +722,7 @@ class Client(proxy.Proxy): ...@@ -719,7 +722,7 @@ class Client(proxy.Proxy):
rpc_connection = RpcConnection(address, disconnect_callback, timeout) rpc_connection = RpcConnection(address, disconnect_callback, timeout)
object.__setattr__(self, "_rpc_connection", rpc_connection) object.__setattr__(self, "_rpc_connection", rpc_connection)
object.__setattr__(self, "_Client__class", None) object.__setattr__(self, "_Client__class", None)
super().__init__(lambda: rpc_connection._proxy) super().__init__(lambda: rpc_connection._proxy, init_once=True)
@property @property
def __class__(self): def __class__(self):
......
...@@ -435,3 +435,35 @@ def test_nonexisting_host(beacon): ...@@ -435,3 +435,35 @@ def test_nonexisting_host(beacon):
raise CommunicationError(str(eee)) from eee raise CommunicationError(str(eee)) from eee
client._rpc_connection.close() client._rpc_connection.close()
def test_disconnect_event_with_closed_server():
url = "tcp://127.0.0.1:12345"
results = gevent.queue.Queue()
def callback(*args):
results.put(args)
with rpc_server(url) as (server, car):
client_car = Client(url)
client_car._rpc_connection.connect()
event.connect(client_car, "test", callback)
event.send(car, "test", 3)
assert results.get() == (3,)
gevent.sleep(0.4)
event.disconnect(client_car, "test", callback)
with rpc_server(url) as (server, car):
# Synchronize
client_car.position
event.send(car, "test", 4)
# the previous event should not update 'results' since
# the event is disconnected
assert len(results) == 0
# close client
client_car._rpc_connection.close()
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