Skip to content

Fix stale response race condition in async search#453

Open
iNalgiev wants to merge 1 commit into
TarekRaafat:masterfrom
iNalgiev:fix/stale-search-race-condition
Open

Fix stale response race condition in async search#453
iNalgiev wants to merge 1 commit into
TarekRaafat:masterfrom
iNalgiev:fix/stale-search-race-condition

Conversation

@iNalgiev
Copy link
Copy Markdown

When a user types quickly, multiple async requests can be in-flight simultaneously. Previously, a slower request for an earlier query for example, a user typing "sea" quickly and continuing to "search" could see results for "sea" overwrite the correct results for "search".

Changes:

  • Added a _requestId counter to the autoComplete context that increments on each search invocation
  • After await getData() resolves, the response is discarded if a newer request was made in the meantime

@iNalgiev
Copy link
Copy Markdown
Author

Any updates? Thanks @TarekRaafat

@TarekRaafat
Copy link
Copy Markdown
Owner

Hello @iNalgiev,

Apologies for my delayed reply, and thanks for your patience and for following up.

Good catch! The race condition you identified is a valid issue. When async data fetches overlap, stale responses can silently overwrite newer results, and the existing debounce alone does not prevent that.

Your approach is clean and minimal, which I appreciate. I have this on my radar and will be addressing it as part of the upcoming v11 release, where the async data flow is getting a broader overhaul. Your fix aligns well with the direction things are heading, and your PR will be used as the base for this specific fix.

I will be publishing the v11 release plan soon, so stay connected for updates.

Thanks for your valuable contribution, much appreciated!

Have a nice day, cheers! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants