test: Add regression tests for BTreeIndex infinite loop with undefined keys#1191
Open
KyleAMathews wants to merge 3 commits intomainfrom
Open
test: Add regression tests for BTreeIndex infinite loop with undefined keys#1191KyleAMathews wants to merge 3 commits intomainfrom
KyleAMathews wants to merge 3 commits intomainfrom
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: |
Contributor
|
Size Change: 0 B Total Size: 90.9 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 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