fix(ec): drop late ed2k server replies after EC client switches to Kad - #37
Merged
got3nks merged 1 commit intoJun 9, 2026
Merged
Conversation
PR amule-project#36 hard-stops the previous Kad search when an EC client starts any new search, blocking late KademliaSearchKeyword(0xffffffff, ...) callbacks from contaminating the new search's m_results[0xffffffff] bucket. The reverse direction was unfixed: late ed2k server replies (TCP Local in ProcessSearchAnswer, UDP Global in ProcessUDPSearchAnswer) keep arriving for seconds after the request was sent and continue calling AddToList with searchID = m_currentSearch. With the EC sentinel `0xffffffff` pinned across all EC searches, those late results land in the new (Kad) search's bucket -- ed2k contamination of a Kad result list, symmetric to the Kad contamination of an ed2k list that PR amule-project#36 fixed. Drop late ed2k replies when the active search type is no longer ed2k. Same shape as PR amule-project#36's StopSearch hoist: cheap one-line gate that closes the bucket on the protocol level. Native-GUI parallel searches: a Kad tab updates m_searchType to KadSearch, so this gate also drops late ed2k packets that would otherwise misroute to the Kad tab's m_results[m_currentSearch]. Pre-existing GUI misrouting bug that wasn't visible because cross- protocol hits in a Kad tab look like generic Kad noise; the right fix there is per-search-object tracking on the ed2k side (mirroring CSearch), out of scope for this hotfix.
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
Symmetric counterpart to #36. That PR hard-stopped the prior Kad search when an EC client starts a new search, blocking late
KademliaSearchKeyword(0xffffffff, ...)callbacks from contaminating the new bucket. The reverse direction — ed2k → Kad — was unfixed: late ed2k server replies (TCP Local fromProcessSearchAnswer, UDP Global fromProcessUDPSearchAnswer) keep arriving for seconds after the original request and continue callingAddToListwithm_currentSearch = 0xffffffff. With the EC sentinel pinned across all EC search types, those late results land in the new Kad search'sm_results[0xffffffff].Fix
Gate the two ed2k result-arrival paths on
m_searchTypebeing an ed2k type. Drop the packet otherwise.Mirrors PR #36's approach (cheap one-line gate, no protocol or state-machine refactor).
Why monolithic / native GUI is (essentially) unaffected
Native GUI parallel searches keep
m_currentSearchat bottom-half IDs allocated byCSearchDlg::StartNewSearch. When a Kad tab is opened,m_searchTypebecomesKadSearchand this gate drops late ed2k replies that would otherwise misroute to the Kad tab's bucket — a pre-existing GUI bug nobody noticed because cross-protocol hits in a Kad tab read as Kad noise.The "correct" long-term fix on the GUI side is per-search-object tracking for ed2k searches mirroring Kad's
CSearch, so late results can route to the right tab. Out of scope here.Test plan
Discovered while verifying #36 on the test VM. Was about to reply on #31 when the contamination appeared in the reverse direction.