-
Notifications
You must be signed in to change notification settings - Fork 161
[fix] BTreeIndex infinite loop with undefined indexed values (issue #1186) #1188
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: +63 B (+0.07%) Total Size: 91 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
Summary
Fixes the infinite loop in
BTreeIndex.takeInternalwhen indexed values areundefined.Root cause
The BTree's
nextHigherPair(undefined)is designed to return the minimum pair whenundefinedis passed (to start iteration from the beginning). However, when the minimum key in the tree ISundefined(because an item's indexed field isundefined), callingnextHigherPair(undefined)after processing returns the same pair again, creating an infinite loop.Fix
The fix introduces a
START_ITERATIONsentinel symbol to distinguish between:fromisundefined)undefinedkey" (when the indexed value isundefined)The loop also detects when
nextPairreturns the same key as was passed in, which indicates we've completed a cycle and should break out.Changes
START_ITERATIONsymbol as a sentinel to represent "start from beginning"takeInternalto use the sentinel and detect cycles when the key doesn't advanceTest plan
should handle undefined indexed values with take and limitshould handle undefined indexed values with takeReversed and limitRepro PR
Reproduction test: #1187
Fixes #1186
🤖 Generated with Claude Code