Skip to content
Source
Sign inSign up
TanStack/db

fix(trailbase): isolate stream lifetimes and add lifecycle oracle #1805

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 7 commits intomain fromrefs/pull/1805/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 9 changed files with 141 additions and 0 deletions (loading 6).

x
0 of 9 viewed, 9 left
5 additions and 0 deletions.changeset/fix-trailbase-stream-lifetimes.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/trailbase-db-collection': patch
+---
+​
+Fix unhandled rejections and resource leaks when a TrailBase subscription closes, fails, or is cleaned up. Drain buffered events before releasing the reader and prevent a canceled startup from canceling a replacement sync session.
135 additions and 0 deletionsnotes/rfc-1657-trailbase.mdAdded
View file
@@ -0,0 +1,135 @@
+# RFC 1657 follow-up: TrailBase stream termination
+​
+Base: origin/main ad043b745. This is the narrow error-handling bug found while
+examining #1521; it does not implement that PR's polling policy.
+​
+- [x] Reproduce with the actual Collection and TrailBase adapter.
+- [x] Add close/error matrix checking reported errors, unhandled rejections,
+ reader lock, cleanup timer, retained rows/status, and absence of extra loads.
+- [x] RED: normal close passes; errored stream leaks an unhandled rejection and
+ keeps its reader locked. Later cleanup can reject again when canceling it.
+ /private/tmp/trailbase-stream-red.log.
+- [x] Fix: observe both settlements of reader.closed, clear interval, release
+ reader, and clear only the matching active-reader reference. The existing
+ listen catch remains the error reporter.
+- [x] GREEN: all12 package runtime tests pass; no type errors. ESLint no errors
+ and one pre-existing require-await warning. Prettier unchanged.
+ /private/tmp/trailbase-stream-green.log.