fix(adapter): prevent dictionary memory leak and runtime dict iterati… - #87
Open
Adityakk9031 wants to merge 1 commit into
Open
fix(adapter): prevent dictionary memory leak and runtime dict iterati…#87Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
…on crash in voice grace window
Contributor
Author
|
@dimavrem22 and @alex-w-99 have a look |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #86
Summary
Fixes an issue in
InkboxAdapter.send()where stale entries inself._voice_recently_closedwere only evaluated and popped for the activechat_id, leading to unbounded dictionary growth and potentialRuntimeError: dictionary changed size during iterationduring concurrent voice call terminations.Problem
_voice_recently_closed[chat_id]recorded the timestamp. However, cleanup (pop) was only attempted if a subsequent message targeted the exact samechat_idafterVOICE_GRACE_SECONDS. Inactive chats or messages sent to different chats never triggered pruning for stale entries.self._voice_recently_closedwithout taking a snapshot during traversal risked raisingRuntimeErrorwhen concurrent asynchronous voice call webhooks mutated the dictionary during execution.Fix Applied
self._voice_recently_closedand removes any timestamp older thanVOICE_GRACE_SECONDS(60 seconds) on everysend()call.list(self._voice_recently_closed.items())) during evaluation to guarantee thread/async safe dictionary mutations.now = time.time()timestamp per evaluation cycle.Verification