fix: dispose serialized execution queue on backend close#73
Merged
Conversation
d033f53 to
a9280e8
Compare
The SQLite backend's serialized execution queue produced unhandled promise rejections when the underlying database was destroyed while operations were still queued (e.g., Cloudflare Workers test teardown resetting Durable Object storage). The root cause: queued tasks that execute after teardown fail with "no such table", and the rejection propagates through the 7+ async wrappers between the queue and the store-level caller. If the caller abandoned the promise, every wrapper layer becomes an independently- unhandled rejected promise. JavaScript offers no way to .catch() a rejection at the bottom of a chain without the wrappers above it also creating unhandled rejections. The fix adds dispose() to the serialized queue, called from backend.close(). Post-dispose tasks return a never-settling promise (pendingForever) so no rejection propagates through any layer. New submissions after dispose reject with BackendDisposedError since the caller actively holds that promise. - Add dispose() with never-settling semantics for in-flight tasks - Add BackendDisposedError to the error hierarchy - Wire backend.close() to call queue.dispose() - Fix createLocalSqliteBackend.close() to call backend.close() before sqlite.close() - Make runWithSerializedQueue and exec functions non-async to eliminate unnecessary promise wrapper allocations Fixes #72
a9280e8 to
5503f91
Compare
Merged
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
@cloudflare/vitest-pool-workers)dispose()to the serialized queue that tracks in-flight promises and attaches.catch()handlers on disposal to prevent unhandled rejectionsbackend.close()now callsqueue.dispose(), andcreateLocalSqliteBackend'sclose()now correctly calls the underlyingbackend.close()before closing the native SQLite connectionclose()throwBackendDisposedErrorFixes #72