-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(mcp): bound and retry OAuth start so a transient stall recovers instead of a blank popup #5874
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a89b243
fix(mcp): bound and retry OAuth start so a transient stall recovers i…
waleedlatif1 cf5563e
fix(mcp): drop the unsafe OAuth-start retry; fail fast without error-…
waleedlatif1 d013b03
fix(mcp): route all bounded-step timeouts to the 504 handler
waleedlatif1 43dcd07
fix(mcp): bound the setOauthRowUser write too so no step escapes the …
waleedlatif1 d793545
fix(mcp): shrink OAuth-start step budgets to fit the 30s client deadl…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import type { Logger } from '@sim/logger' | ||
| import { toError } from '@sim/utils/errors' | ||
|
|
||
| /** Thrown when a `timedStep`-bounded operation doesn't settle within its budget. */ | ||
| export class OauthStepTimeoutError extends Error { | ||
| constructor(step: string, ms: number) { | ||
| super(`MCP OAuth step "${step}" did not settle within ${ms}ms`) | ||
| this.name = 'OauthStepTimeoutError' | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Times and bounds one awaited step of an OAuth route so a stalled operation surfaces | ||
| * as a labeled, logged error instead of hanging the request (and the browser popup | ||
| * waiting on it) forever. The losing promise is not cancelled — a wedged DB/socket op | ||
| * can't be — so it settles in the background with its rejection swallowed; the point is | ||
| * that the request stops waiting on it and the logs name the exact step that stalled. | ||
| */ | ||
| export function makeTimedStep(logger: Logger) { | ||
| return async function timedStep<T>(step: string, ms: number, fn: () => Promise<T>): Promise<T> { | ||
| const start = Date.now() | ||
| logger.info(`OAuth step start: ${step}`) | ||
| const work = Promise.resolve(fn()) | ||
| work.catch(() => {}) | ||
| let timer: ReturnType<typeof setTimeout> | undefined | ||
| try { | ||
| const value = await Promise.race([ | ||
| work, | ||
| new Promise<never>((_, reject) => { | ||
| timer = setTimeout(() => reject(new OauthStepTimeoutError(step, ms)), ms) | ||
| timer.unref?.() | ||
| }), | ||
| ]) | ||
| logger.info(`OAuth step done: ${step} (${Date.now() - start}ms)`) | ||
| return value | ||
| } catch (error) { | ||
| logger.error(`OAuth step failed: ${step} (${Date.now() - start}ms)`, { | ||
| error: toError(error).message, | ||
| }) | ||
| throw error | ||
| } finally { | ||
| clearTimeout(timer) | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.