Skip to content
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

Unexpected results with concurrent requests #115

Open
vwong opened this issue Sep 11, 2024 · 2 comments
Open

Unexpected results with concurrent requests #115

vwong opened this issue Sep 11, 2024 · 2 comments

Comments

@vwong
Copy link

vwong commented Sep 11, 2024

When the API is slow, I may decide to explore a different endpoint (eg, to see if the API is working). When this happens, I expect the previous request to be aborted, and replaced with a new request. Instead, what I observe are concurrent requests.

Since the UI is very much geared towards a single request/response pair, when the concurrent requests return out-of-order, I see unexpected results.

A few possible solutions:

  • block the UI to prevent changes when there is an in-flight request, and offer an "abort" feature
  • automatically abort the previous request as necessary if request parameters change

I vote for the latter.

@toedter
Copy link
Owner

toedter commented Sep 11, 2024

Thx for reporting this. I will take a look, I would guess due to the 'single thread / non-blocking IO' nature, the second option would not be so easy to implement. If you have any ideas, a PR would be welcome.

@vwong
Copy link
Author

vwong commented Sep 11, 2024

I haven't the time to learn up RxJs to create a PR right now, but you'll need something like https://developer.mozilla.org/en-US/docs/Web/API/AbortController There's a nice example therein.

When a subsequent request is triggered, the preceding request will be aborted at the HTTP level - it doesn't run in the background to completion. We don't have to deal with the older, redundant, and possibly out-of-order response, because there will be none! There will only ever be at most 1 in-flight request. A sufficiently smart server can even detect the disconnect from the client (ECONNRESET), and abort the remainder of the work to fulfill the request in order to conserve resources - workload dependent of course.

I guess in RxJs terms, you'll get N events for different requests (URIs, headers, etc.), but <= N events of actual responses displayed to the UI, the actual number depends on the request rate vs the response rate.

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

No branches or pull requests

2 participants