fix: use oneshot channel to send search outcome back#190
Merged
Conversation
ldm0
reviewed
Apr 28, 2026
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.
Goal
eliminate usage of MPMC channel for search job to make the http api works with UI.
Background
http api and UI both interact with the background loop since it's the background loop that receives the search job and do the actual search.
but current usage of MPMC channel may cause race condition, resulting in non-deterministic behavior.
Solution
add a
SenderinSearchJob(this behavior aligns withNodeInfoRequest) so the background loop could send the result back via it.Tests
https://gist.github.com/hsqStephenZhang/bd14bd8021be3b49c33afb2194a97711 this test case test the race condition via simulating two concurrrent searches.
it failed before the change, but works after this PR, the new test case is here).