Skip to content

Commit

Permalink
Fixed #527 by releasing/notifying prior to dispatch (breaking commit 2…
Browse files Browse the repository at this point in the history
  • Loading branch information
comrumino committed Feb 21, 2023
1 parent 64ff98d commit 1bff083
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def serve(self, timeout=1, wait_for_lock=True): # serving
return self._recv_event.wait(timeout.timeleft())
else:
return False
# Assume the receive rlock is acquired and incremented
# Assume the receive rlock is acquired and incremented. For except/else, we release and notify of _recv_event.
try:
data = None # Ensure data is initialized
data = self._channel.poll(timeout) and self._channel.recv()
Expand All @@ -442,17 +442,16 @@ def serve(self, timeout=1, wait_for_lock=True): # serving
with self._recv_event:
self._recv_event.notify_all()
raise
# At this point, the recvlock was acquired once, we must release once before exiting the function
if data:
# Dispatch will unbox, invoke callbacks, etc.
self._dispatch(data)
else:
# We must release once, notify, and THEN dispatch (see issue #527).
self._recvlock.release()
with self._recv_event:
self._recv_event.notify_all()
return True
else:
self._recvlock.release()
return False
if data:
self._dispatch(data) # Dispatch will unbox, invoke callbacks, etc.
return True
else:
return False

def _serve_bound(self, timeout, wait_for_lock):
"""Serves messages like `serve` with the added benefit of making request/reply thread bound.
Expand Down

0 comments on commit 1bff083

Please sign in to comment.