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(client): Fix cleanup of Client._waiters dict #129

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
15 changes: 7 additions & 8 deletions rstream/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def __init__(
}

self._corr_id_seq = utils.MonotonicSeq()
self._waiters: dict[
tuple[constants.Key, Optional[int]], set[asyncio.Future[schema.Frame]]
] = defaultdict(set)
self._waiters: dict[tuple[constants.Key, Optional[int]], asyncio.Future[schema.Frame]] = {}

self._tasks: dict[str, asyncio.Task[None]] = {}
self._handlers: dict[Type[schema.Frame], dict[str, HT[Any]]] = defaultdict(dict)
Expand Down Expand Up @@ -155,8 +153,8 @@ def wait_frame(

fut: asyncio.Future[schema.Frame] = asyncio.Future()
_key = frame_cls.key, corr_id
self._waiters[_key].add(fut)
fut.add_done_callback(self._waiters[_key].discard)
self._waiters[_key] = fut
fut.add_done_callback(lambda _: self._waiters.pop(_key, None))
return utils.TimeoutWrapper(fut, timeout)

async def sync_request(self, frame: schema.Frame, resp_schema: Type[FT], raise_exception=True) -> FT:
Expand Down Expand Up @@ -198,11 +196,12 @@ async def _listener(self) -> None:
break

logger.debug("Received frame: %s", frame)
_key = frame.key, frame.corr_id

while self._waiters[_key]:
fut = self._waiters[_key].pop()
_key = frame.key, frame.corr_id
fut = self._waiters.get(_key)
if fut is not None:
fut.set_result(frame)
del self._waiters[_key]

for _, handler in self._handlers.get(frame.__class__, {}).items():
try:
Expand Down
Loading