Commit 2a796ff
committed
Fix root cause of Electric infinite loop with ORDER BY/LIMIT queries
The infinite loop occurred because `loadMoreIfNeeded` kept trying to load
data even when the local index was exhausted. This happened when:
1. TopK had fewer items than limit (WHERE filtered out data)
2. loadMoreIfNeeded tried to load more → no local data found
3. Loop continued indefinitely since TopK still needed data
Root cause fix:
- Add `localIndexExhausted` flag to CollectionSubscriber
- Track when local index has no more data for current cursor
- Stop calling loadMoreIfNeeded when exhausted
- Reset flag when new data arrives from sync layer (inserts)
- requestLimitedSnapshot now returns boolean indicating if data was found
Error handling improvements (per review feedback):
- D2.run() now throws Error when iteration limit exceeded
- Caller catches and calls transitionToError() for proper error state
- requestLimitedSnapshot returns false when iteration limit hit
- Live query properly shows error state if safeguard limits are hit
This fixes the issue for both eager and progressive syncMode.1 parent d8f95da commit 2a796ff
File tree
4 files changed
+76
-24
lines changed- packages
- db-ivm/src
- db/src
- collection
- query/live
4 files changed
+76
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
73 | 71 | | |
74 | | - | |
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| 413 | + | |
| 414 | + | |
413 | 415 | | |
414 | 416 | | |
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
418 | 420 | | |
419 | | - | |
| 421 | + | |
420 | 422 | | |
421 | 423 | | |
422 | 424 | | |
| |||
508 | 510 | | |
509 | 511 | | |
510 | 512 | | |
| 513 | + | |
511 | 514 | | |
512 | 515 | | |
513 | | - | |
514 | | - | |
| 516 | + | |
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
518 | 520 | | |
519 | 521 | | |
| 522 | + | |
520 | 523 | | |
521 | 524 | | |
522 | 525 | | |
| |||
611 | 614 | | |
612 | 615 | | |
613 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
614 | 625 | | |
615 | 626 | | |
616 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
356 | 354 | | |
357 | | - | |
| 355 | + | |
358 | 356 | | |
359 | 357 | | |
360 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
361 | 368 | | |
362 | 369 | | |
363 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
301 | 307 | | |
302 | 308 | | |
303 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
304 | 318 | | |
305 | 319 | | |
306 | 320 | | |
307 | 321 | | |
308 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
309 | 329 | | |
310 | 330 | | |
311 | 331 | | |
| |||
320 | 340 | | |
321 | 341 | | |
322 | 342 | | |
323 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
324 | 356 | | |
325 | 357 | | |
326 | 358 | | |
| |||
342 | 374 | | |
343 | 375 | | |
344 | 376 | | |
345 | | - | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
346 | 382 | | |
347 | 383 | | |
348 | | - | |
| 384 | + | |
349 | 385 | | |
350 | 386 | | |
351 | 387 | | |
| |||
369 | 405 | | |
370 | 406 | | |
371 | 407 | | |
372 | | - | |
| 408 | + | |
| 409 | + | |
373 | 410 | | |
374 | 411 | | |
375 | 412 | | |
| |||
0 commit comments