feat: add timeout to detectCurrentOrigin() to avoid hanging forever - #2337
Open
ayushsingh82 wants to merge 1 commit into
Open
feat: add timeout to detectCurrentOrigin() to avoid hanging forever#2337ayushsingh82 wants to merge 1 commit into
ayushsingh82 wants to merge 1 commit into
Conversation
If window.opener exists but the origin-broadcast message is never received (e.g. the opener never responds), detectCurrentOrigin() polled via setInterval with no timeout or reject path, hanging the awaiting caller indefinitely. Add a 30s timeout that clears the interval and rejects with a descriptive error instead. Fixes canton-network#2228 Signed-off-by: ayushsingh82 <ayushsinghmi711@gmail.com>
Contributor
Author
|
@alexmatson-da whenever you have a chance, would appreciate a look at this one. |
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
detectCurrentOrigin()(wallet-gateway/remote/src/web/frontend/listeners.ts) pollsstateManager.currentOrigin.get()viasetIntervalwhile waiting for the opener window's origin-broadcast message, with no timeout or reject path.window.openerexists but that message is never received (e.g. the opener never responds), the returned promise hangs forever, and every one of the ~40 call sites across the frontend (await detectCurrentOrigin()) hangs with it.DETECT_CURRENT_ORIGIN_TIMEOUT_MS(30s) timeout that clears the interval and rejects with a descriptive error instead of hanging silently.Fixes #2228 (the "Consider a timeout for detectCurrentOrigin()" checklist item).
Test plan
listeners.test.tscovering: no-opener resolves immediately, resolves once the broadcast message setscurrentOrigin, and rejects after the timeout when the message never arrives.npx vitest run --project browser src/web/frontend/listeners.test.ts— 3/3 passing.eslintclean on all 3 changed files.tsc --noEmitclean on the touched files (pre-existing unrelated module-resolution errors in this package come from other packages needing a full monorepo build, not from this change).