fix(B1): Future-Cleanup bei Disconnect — _pending_results werden mit DDPNotConnected aufgelöst
- _cancel_pending_results() löst alle pending Futures mit DDPNotConnected auf - disconnect() ruft _cancel_pending_results() nach Socket-Close - _reader_loop Exit-Pfad ruft _cancel_pending_results() nach self.connected=False - PulseController._pulse_tick_async fängt Exception (inkl. DDPNotConnected) und fällt auf REST zurück - 2 neue Tests: test_disconnect_clears_pending_futures, test_reader_loop_exit_clears_pending_futures
This commit is contained in:
@@ -451,6 +451,9 @@ class DDPClient:
|
||||
except Exception:
|
||||
break
|
||||
self.connected = False
|
||||
# B1: Reader loop exited — cancel all pending Futures so callers
|
||||
# (e.g. PulseController) get DDPNotConnected and can fall back to REST.
|
||||
self._cancel_pending_results()
|
||||
logger.debug("DDP reader thread exited")
|
||||
|
||||
def is_alive(self, max_silence: float = 300.0) -> bool:
|
||||
@@ -768,6 +771,21 @@ class DDPClient:
|
||||
len(stale_ids),
|
||||
)
|
||||
|
||||
def _cancel_pending_results(self) -> None:
|
||||
"""B1: Resolve all pending Futures with DDPNotConnected and clear the store.
|
||||
|
||||
Called on disconnect and reader-loop exit to prevent memory leaks
|
||||
from Futures that would otherwise hang forever waiting for a result
|
||||
message that will never arrive.
|
||||
"""
|
||||
with self._result_lock:
|
||||
for msg_id, future in list(self._pending_results.items()):
|
||||
if not future.done():
|
||||
future.set_exception(
|
||||
DDPNotConnected("DDP connection closed — pending result cancelled")
|
||||
)
|
||||
self._pending_results.clear()
|
||||
|
||||
def disconnect(self):
|
||||
self._running = False
|
||||
if self.sock:
|
||||
@@ -777,6 +795,9 @@ class DDPClient:
|
||||
pass
|
||||
self.sock = None
|
||||
self.connected = False
|
||||
# B1: Cancel all pending Futures so callers (e.g. PulseController)
|
||||
# get DDPNotConnected and can fall back to REST instead of hanging.
|
||||
self._cancel_pending_results()
|
||||
self._sub_rooms.clear()
|
||||
|
||||
# Bug 7: reconnect_and_restore() ist deprecated — sie umgeht M13 GC.
|
||||
|
||||
Reference in New Issue
Block a user