Skip to content

Don't cache rejected promises - #39

Merged
langsamu merged 2 commits into
mainfrom
cached-cancel
Sep 4, 2026
Merged

Don't cache rejected promises#39
langsamu merged 2 commits into
mainfrom
cached-cancel

Conversation

@langsamu

@langsamu langsamu commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Previously, when an IdP (issuer/AS) selector modal was cancelled (by the user clicking ESC or the 'cancel' button or by timeout) then subsequent invocations of the same UI were short-circuited to cancellation.

This was because in various places promises were put into Map caches even if they were rejected.

This change ensures that only results of resolved promises are cached.

@langsamu
langsamu marked this pull request as ready for review September 2, 2026 15:31

@jeswr jeswr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to remove the entry on promise rejection - so that the cache is still made use of when multiple requests are issued in parallel.

You'll then need some try/catch logic so that if a cached promise rejects you then retry.

@jeswr

jeswr commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Even better would be to track all of the consumers waiting for a cached promise to resolve; and only cancel the operation if all of the consumers cancel.

@langsamu

langsamu commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

It would be better to remove the entry on promise rejection - so that the cache is still made use of when multiple requests are issued in parallel.

You'll then need some try/catch logic so that if a cached promise rejects you then retry.

I agree that this change might lead to more requests because parallel requests to the same URI might find an empty cache, in which case they'll invoke the undetlying operation multiple times.

But this change is intended only to fix my previous faulty implementation, where I was caching rejected promises. I think that some degradation in the caching layer for the parallel case is currently preferable to a complex 'multi-threaded' mitigation that I am not yet comfortable implementing.

I'm dropping one block of asyncronicity here because I was doing it wrong. I'd rather not replace it with another because I'm likely go wrong again.

@langsamu
langsamu requested a review from jeswr September 3, 2026 14:25
@langsamu
langsamu merged commit f9685c9 into main Sep 4, 2026
5 checks passed
@langsamu
langsamu deleted the cached-cancel branch September 4, 2026 08:55
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