-
Notifications
You must be signed in to change notification settings - Fork 201
[FIX] Async topic validator issue #1156
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
base: main
Are you sure you want to change the base?
Conversation
|
Also please note: they might be pyrefly errors that are pre-existing in the repo |
…11/py-libp2p into async-topic-validator-issue-1118 merge main into async-topic-validator-issue-1118
|
@acul71 , @sumanjeet0012, @Winter-Soren : CI/CD failure in this issue is not related to this PR. Please visit the logs: =========================== short test summary info ============================ Wish if you could open a new PR for arriving at a good conclusion on this issue. |
Facing similar issue in one of my PRs, whoever is working on providing the fix please also verify the ci failure address in the issue #1164 |
What was wrong?
Issue #1118
When using async topic validators in GossipSub, the pubsub service crashes with
KeyErrorinmcache.shift().Root cause: Race condition in
MessageCache.put()mcache.put(msg)after validation completesput()has two operations:self.msgs[mid] = msg- overwrites if exists (dict count stays 1)self.history[0].append(...)- always appends (list count becomes 2)msgs, but 2 entries inhistoryfor the same message IDshift()rotates the history window, it tries topop()the same mid twiceKeyErrorbecause message was already removedHow was it fixed?
1. Duplicate detection in
put()Added early return if message ID already exists:
2. Defensive pop in
shift()Changed from
pop(mid)topop(mid, None)for additional safety:Why this works in Trio: Since
put()is synchronous (noawaitpoints), each call runs atomically. First call adds to bothmsgsandhistory, second call findsmid in self.msgsand returns early. No duplicate history entries can be created.Files changed:
libp2p/pubsub/mcache.py- Added duplicate check + defensive poptests/core/pubsub/test_mcache_race_condition.py- Tests that fail before fix, pass afterImpact:
put())To-Do
Cute Animal Picture
Before fix:

After fix:
