-
Notifications
You must be signed in to change notification settings - Fork 161
test: Add regression tests for BTreeIndex infinite loop with undefined keys #1191
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
…lues (issue #1186) This test demonstrates the infinite loop bug that occurs when calling take() on a BTreeIndex containing items with undefined indexed values. The bug is in takeInternal() where nextHigherPair(undefined) returns the minimum pair [undefined, undefined], then key is set to pair[0] (undefined), causing the same pair to be returned infinitely since the while condition (pair !== undefined) is always true for arrays. https://claude.ai/code/session_01RKBKXMoKVe1hSXGy3VVEFo
|
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
|
🎯 Changes
This PR adds comprehensive regression tests for GitHub issue #1186, which describes an infinite loop in
BTreeIndex.takeInternalwhen usingorderBy()andlimit()on collections containing items with undefined indexed values.The test suite includes:
take()andtakeReversed()with undefined indexed valuesBTreeIndex.takeInternalwhen using orderBy and limit withundefinedindexed values #1186 using live queries withorderByandlimitwhere,orderBy, andlimitwith undefined valuesAll tests include a 5-second timeout to catch infinite loops during test execution.
Root Cause (documented in test comments):
When
nextHigherPair(undefined)is called, it returns the minimum pair from the B-tree. If that minimum key is itselfundefined, the method returns[undefined, undefined]. After processing, the code setskey = pair[0](which isundefined) and callsnextHigherPair(undefined)again, returning the same pair and creating an infinite loop.✅ Checklist
pnpm test:pr.🚀 Release Impact
Note: This is a test-only addition that documents the bug for future reference and validation once the underlying issue is fixed.
https://claude.ai/code/session_01RKBKXMoKVe1hSXGy3VVEFo