fix(signal): use FIFO eviction for sent-timestamp tracking - #3692
Closed
dieutx wants to merge 1 commit into
Closed
Conversation
Replace plain set with OrderedDict for _recent_sent_timestamps so that eviction always removes the oldest entry instead of an arbitrary one. The previous set.pop() could discard newer timestamps while keeping stale ones indefinitely, degrading echo-back filtering over time.
3 tasks
Contributor
Author
|
Closing — minor edge case that rarely triggers in practice. |
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.
Summary
Signal's echo-back filter (
_recent_sent_timestamps) usesset.pop()to evict old entries when the set exceeds 50 items. Since Python sets are unordered,pop()removes an arbitrary element — it might evict the newest timestamp while keeping a stale one from hours ago. Over time this degrades the echo-back filter: legitimate sent timestamps get evicted early, causing the adapter to re-process its own outbound messages as inbound.Same class of bug as #3490 (email
_seen_uidsgrowing unbounded).Root Cause
set.pop()on line 626 ofgateway/platforms/signal.pydoesn't guarantee oldest-first eviction. Sets have no insertion order in their iteration/pop behavior, so the eviction is effectively random.Fix
Replace the plain
setwithcollections.OrderedDict(used as an ordered set withNonevalues):set()→OrderedDict().discard(ts)→.pop(ts, None).add(ts)→[ts] = None,.pop()→.popitem(last=False)OrderedDict.popitem(last=False)always removes the oldest entry — O(1), deterministic FIFO.Tests
6 new tests in
tests/gateway/test_signal_timestamp_eviction.py:38 pre-existing signal tests + 6 new = 44 passed.