Repository navigation
feat(core): add timeout/signal options to waitForInstanceReady - #157
Merged
Merged
Conversation
An unbounded while loop with no escape caused production hangs when
instances never reached 'running' state. Adds opts.timeoutMs (default
300s), opts.pollIntervalMs (default 1000ms), and opts.signal to allow
caller control over the wait budget.
On timeout: rejects with InstanceReadyTimeoutError (exported).
On abort: rejects with Error{ name: 'AbortError' }.
Breaking behavior change: the finite default (300s) replaces the old
infinite loop. Callers that want the old infinite behavior can pass
{ timeoutMs: Infinity }.
Closes #156. Ref: Eyevinn/open-media-convert#160.
Co-Authored-By: Claude <noreply@anthropic.com>
The implementation throws a plain Error with .name = 'AbortError'
because DOMException is not available in the es2022 lib target.
Change abort test assertions from toThrow(AbortError) to
toMatchObject({ name: 'AbortError' }) so they match the actual
error shape. Also replace fake-timer patterns with pollIntervalMs: 0
for simpler, more reliable async test flow.
Co-Authored-By: Claude <noreply@anthropic.com>
…r dep
Move waitForInstanceReady from core.ts into waitForInstanceReady.ts.
core.ts re-exports it transparently for backwards compatibility.
The test (waitForInstanceReady.test.ts) mocks ./core and calls
waitForInstanceReady via jest.requireActual('./core'). Since both
waitForInstanceReady and getInstanceHealth were in the same module,
the mock factory could not intercept internal calls — the actual
function's closure held a direct reference to the real getInstanceHealth.
Fix: put waitForInstanceReady in its own file. It uses a lazy
require('./core') inside the loop body (not at module load time)
so Jest's mock registry is consulted at call time, when the mock
is fully initialized. This avoids the circular-dep race that
defeated the earlier import * as coreModule approach.
Co-Authored-By: Claude <noreply@anthropic.com>
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
Closes #156. Ref: Eyevinn/open-media-convert#160.
waitForInstanceReadywas an unboundedwhileloop with no timeout, attempt cap, or AbortSignal. A hung instance could cause anyfinallyblock downstream of this call to never execute, leaking guards, locks, or other resources. In production, this caused atranscoderNamesBeingCreatedguard in open-media-convert to permanently block that queue name until the MyApp was restarted.Changes
packages/core/src/core.ts— Added optional 4th argumentopts?: WaitForInstanceReadyOptions:timeoutMs?: number(default 300,000ms / 5 min)pollIntervalMs?: number(default 1000ms)signal?: AbortSignalOn timeout: rejects with
InstanceReadyTimeoutError.On abort: rejects with
Error{ name: 'AbortError' }(avoidsDOMExceptionwhich requires the DOM lib).packages/core/src/errors.ts— Added exportedInstanceReadyTimeoutError extends Error.packages/core/src/index.ts— Re-exportsInstanceReadyTimeoutError.packages/core/src/waitForInstanceReady.test.ts— New test file covering: resolves on success, rejects withInstanceReadyTimeoutErroron timeout, rejects with AbortError on signal abort.packages/core/package.json— Version bumped to next minor.Breaking behavior change
The finite default (300s) replaces the old infinite loop. Callers who want the old infinite behavior can pass
{ timeoutMs: Infinity }. This is documented in the commit message.Lessons
DOMExceptionis not available when tsconfiglibis['es2022']withoutdom. Usenew Error(...); err.name = 'AbortError'instead for abort signals in Node-only packages.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com