Skip to content

feat(bson-parsing): terminate worker if execution exceeds 2mins COMPASS-11147 - #893

Draft
mabaasit wants to merge 4 commits into
restrict-worker-scopefrom
timout-long-running-worker
Draft

mabaasit wants to merge 4 commits into
restrict-worker-scopefrom
timout-long-running-worker

Conversation

@mabaasit

@mabaasit mabaasit commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Description

COMPASS-11147

Open Questions

Checklist


Stack created with GitHub Stacks CLI • Give Feedback 💬

@mabaasit
mabaasit requested review from a team as code owners September 21, 2026 08:51
@mabaasit
mabaasit added this pull request to stack #894 September 21, 2026 08:51
@mabaasit
mabaasit requested review from Anemy and removed request for a team September 21, 2026 08:51
/** Close the worker after being idle for 30sec */
const IDLE_TIMEOUT_MS = 30_000;
/** Default execution timeout for worker requests */
const DEFAULT_EXECUTION_TIMEOUT_MS = 120_000;

@Anemy Anemy Sep 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should consumers be able to pass this timeout? Will 0 indicate no timeout?

@mabaasit mabaasit Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's a good idea, will implement this.

@mabaasit mabaasit changed the title feat(bson-parsing): terminate worker if execution exceeds 2mins feat(bson-parsing): terminate worker if execution exceeds 2mins COMPASS-11147 Sep 22, 2026
@mabaasit
mabaasit marked this pull request as draft September 22, 2026 08:58
Copilot AI lite review requested due to automatic review settings September 23, 2026 11:19
@mabaasit
mabaasit force-pushed the timout-long-running-worker branch from 2bce04b to 887c77d Compare September 23, 2026 11:19

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Moderate worker-concurrency and test-environment cleanup issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 2 Low severity

Open (4)
What changed in this PR

Adds configurable two-minute execution timeouts for BSON parser workers, including worker termination and slow-worker tests.

Changes:

  • Adds timeout handling and worker termination.
  • Exposes timeout options through the parser API.
  • Adds slow-worker fixtures, tests, and related dependency/lint configuration.
File Reviewed changes Findings
packages/​shell-bson-parser/​tsconfig-lint.json Excludes test fixtures from lint type checking. No findings.
packages/​shell-bson-parser/​test/​fixtures/​slow-worker.mjs Adds a deliberately slow worker fixture. No findings.
packages/​shell-bson-parser/​src/​worker-client.ts Implements request timers and worker termination. moderate (2 votes): global termination can target the wrong worker during concurrent initialization, leaving the timed-out worker active and leaking its blob URL. Initialization must be serialized or termination made instance-aware. nit (3 votes): correct the duplicated/incorrect verb in the comment.
packages/​shell-bson-parser/​src/​index.ts Exposes execution timeout options. No findings.
packages/​shell-bson-parser/​src/​index.spec.ts Adds timeout and worker replacement tests. moderate (3 votes, also line 233): restore or delete TEST_WORKER_SCRIPT_URL when initially unset. moderate (1 vote): the cleanup truthiness check leaks the override when initially undefined. nit (2 votes): correct the comment to say the request “times out.”
packages/​shell-bson-parser/​package.json Adds the worker test dependency. No findings.
packages/​shell-bson-parser/​.eslintrc.cjs Excludes fixture files from ESLint. No findings.
package-lock.json Locks the new dependency. No findings.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +50 to +52
if (initialWorkerScriptUrl) {
process.env.TEST_WORKER_SCRIPT_URL = initialWorkerScriptUrl;
}
Comment on lines +120 to +123
terminateWorker(
new Error(`Worker execution timed out after ${executionTimeoutMs}ms`),
);
}, executionTimeoutMs);
});

it('spins up a fresh worker for the next call after a timeout kill', async function () {
await callWorker([1000]).catch(() => {}); // timeouts out
const promise = new Promise<T>((resolve, reject) => {
pending.set(id, { resolve, reject });
const executionTimer = setTimeout(() => {
// Terminate the worker is this message is taking too long to execute,
@mabaasit
mabaasit force-pushed the timout-long-running-worker branch from 887c77d to b96a2f9 Compare September 23, 2026 14:48
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.

3 participants