-
Notifications
You must be signed in to change notification settings - Fork 158
Handle aborted requests during collection cleanup #1174
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
base: main
Are you sure you want to change the base?
Conversation
|
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 90.9 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
|
any ETA on this? would really help stabilize our CI checks :) |
When a collection is cleaned up while requestSnapshot or fetchSnapshot calls are still in-flight, the abort signal causes these calls to fail with HTTP 409 "must-refetch" errors. These errors were propagating as unhandled promise rejections because they bypassed the onError handler (which only catches errors from the ShapeStream subscription). This fix: - Passes the abort signal to createLoadSubsetDedupe - Wraps requestSnapshot and fetchSnapshot calls in try-catch blocks - Silently ignores errors when the signal is aborted (during cleanup) - Re-throws errors if the signal is not aborted (real errors)
c080dc6 to
ba076b7
Compare
Summary
Fix unhandled promise rejections when collections are cleaned up while
requestSnapshotorfetchSnapshotcalls are still in-flight. Adds comprehensive test coverage for the error suppression behavior.Reviewer Guidance
Root Cause
When a collection is cleaned up, the abort controller signals cancellation. However, any in-flight
requestSnapshotorfetchSnapshotcalls would reject (often with 409 "must-refetch" errors), and these rejections were unhandled—causing console warnings and potential issues in error-sensitive environments.Approach
createLoadSubsetDedupe: The abort signal is now available in the subset loading logicfetchSnapshot(progressive mode) andrequestSnapshot(on-demand mode) are now wrappedsignal.abortedbefore re-throwing: If the signal is aborted, errors are logged at debug level and suppressed; otherwise, they propagate normallyhandleSnapshotErrorKey Invariants
signal.aborted === true) are silently ignoredsignal.aborted === false) are re-thrownAbortControllerin tests now actually aborts the signal whenabort()is calledNon-goals
Trade-offs
The silent-failure-hunter agent identified that catching ALL errors when aborted (not just abort-related ones) could theoretically hide unrelated errors that happen to occur during cleanup. However:
Verification
Files Changed
src/electric.tshandleSnapshotErrorhelper, refactor duplicate catch blockstests/electric.test.tsChecklist
pnpm test:pr.Release Impact
🤖 Generated with Claude Code