Skip to content

fix(mcp): clear timeout timer in bootstrapOneWorkspace#88

Merged
khaliqgant merged 1 commit intomainfrom
fix/bootstrap-timer-leak
Mar 16, 2026
Merged

fix(mcp): clear timeout timer in bootstrapOneWorkspace#88
khaliqgant merged 1 commit intomainfrom
fix/bootstrap-timer-leak

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Mar 15, 2026

When doBootstrap() resolves before the timeout, the setTimeout timer was never cleared, holding a ref on the event loop for up to timeoutMs (default 5s) and preventing clean process shutdown.

Fix: Store the timer reference and clearTimeout() on success.

Addresses Devin review comment on PR #86.

All 222 MCP tests passing.


Open with Devin

When doBootstrap() resolves before the timeout, the setTimeout timer
was never cleared, holding a ref on the event loop and preventing
clean shutdown. Now clears the timer on success.
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +76 to +78
const result = await Promise.race([doBootstrap(), timeout]);
clearTimeout(timer!);
return result;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Timer not cleared when Promise.race rejects, leaking the timeout on the error path

The new clearTimeout(timer!) on line 77 only executes on the success path. When doBootstrap() rejects (e.g., registerOrRotate throws a network error) before the timeout fires, Promise.race rejects and control jumps to the catch block at line 79, skipping the clearTimeout. The timer remains active for up to timeoutMs (default 5 seconds), keeping the Node.js event loop alive and potentially delaying process exit — especially noticeable in the stdio/CLI transport where bootstrapWorkspaces (packages/mcp/src/transports.ts:99-101) runs all workspaces concurrently and multiple leaked timers can accumulate.

Suggested change
const result = await Promise.race([doBootstrap(), timeout]);
clearTimeout(timer!);
return result;
const result = await Promise.race([doBootstrap(), timeout]);
clearTimeout(timer!);
return result;
} catch (err) {
clearTimeout(timer!);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@github-actions
Copy link
Copy Markdown

Preview deployed!

Environment URL
API https://pr88-api.relaycast.dev
Health https://pr88-api.relaycast.dev/health
Observer https://pr88-observer.relaycast.dev/observer

This preview shares the staging database and will be cleaned up when the PR is merged or closed.

Run E2E tests

npm run e2e -- https://pr88-api.relaycast.dev --ci

Open observer dashboard

https://pr88-observer.relaycast.dev/observer

@khaliqgant khaliqgant merged commit af281a9 into main Mar 16, 2026
4 checks passed
@khaliqgant khaliqgant deleted the fix/bootstrap-timer-leak branch March 16, 2026 17:34
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.

1 participant