-
Notifications
You must be signed in to change notification settings - Fork 130
fix for schedular bug with lazy left-join sources #898
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
Conversation
🦋 Changeset detectedLatest commit: 0861ff9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
2123063 to
d06f565
Compare
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: +150 B (+0.17%) Total Size: 86.5 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
packages/db/src/scheduler.ts
Outdated
| return ( | ||
| typeof dep === `object` && | ||
| dep !== null && | ||
| typeof (dep as { hasPendingGraphRun?: unknown }).hasPendingGraphRun === |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes more sense to type this function's dep argument as any such that you don't need this typecast here.
|
🎉 This PR has been released! Thank you for your contribution! |
Fixes #813
Failed test run showing reproduction: https://github.com/TanStack/db/actions/runs/19632437525/job/56215175357?pr=898
Summary
Fix scheduler deadlocks from lazy left-join sources (e.g., the nested left join in the “should handle optimistic mutations with nested left joins without scheduler errors” test) by only blocking on dependencies that are actually enqueued or have pending work in the same transaction. Non-enqueued lazy deps are treated as satisfied, preventing unresolved dependency errors.
Background: How the scheduler and live queries interact
Scheduler detected unresolved dependencies for context ....Original issue
What changed (code)
packages/db/src/scheduler.tsPendingAwareJobtype andisPendingAwareJobguard to removeanycasting when checking for pending work.hasPendingGraphRun.packages/db/src/query/live/collection-config-builder.tshasPendingGraphRunso dependents can detect when a builder has work pending in a transaction (used by the scheduler dependency logic).autoCommit: falseto keep the transaction open during the race, ensuring the scheduler ordering is exercised without dropping optimistic state prematurely.Why this fixes the problem
Testing
pnpm vitest packages/db/tests/query/scheduler.test.ts -t "live query scheduler"(all 10 tests now pass, covering the deadlock scenario and the stale-read race).Notes
.changeset/soft-lazy-deps.md(patch for@tanstack/db).