Skip to content

feat: add timeout to detectCurrentOrigin() to avoid hanging forever - #2337

Open
ayushsingh82 wants to merge 1 commit into
canton-network:mainfrom
ayushsingh82:ayush/origin-detect-timeout-2228
Open

feat: add timeout to detectCurrentOrigin() to avoid hanging forever#2337
ayushsingh82 wants to merge 1 commit into
canton-network:mainfrom
ayushsingh82:ayush/origin-detect-timeout-2228

Conversation

@ayushsingh82

Copy link
Copy Markdown
Contributor

Summary

  • detectCurrentOrigin() (wallet-gateway/remote/src/web/frontend/listeners.ts) polls stateManager.currentOrigin.get() via setInterval while waiting for the opener window's origin-broadcast message, with no timeout or reject path.
  • If window.opener exists 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.
  • Added a 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

  • Added listeners.test.ts covering: no-opener resolves immediately, resolves once the broadcast message sets currentOrigin, and rejects after the timeout when the message never arrives.
  • npx vitest run --project browser src/web/frontend/listeners.test.ts — 3/3 passing.
  • eslint clean on all 3 changed files.
  • tsc --noEmit clean 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).

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>
@ayushsingh82

Copy link
Copy Markdown
Contributor Author

@alexmatson-da whenever you have a chance, would appreciate a look at this one.

@mjuchli-da mjuchli-da changed the title Add timeout to detectCurrentOrigin() to avoid hanging forever feat: add timeout to detectCurrentOrigin() to avoid hanging forever Aug 21, 2026
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.

Follow-up multi-session cleanups

1 participant