Commit d8f95da
committed
Fix potential infinite loops in graph execution and data loading
Add iteration safeguards to prevent infinite loops that can occur
when using Electric with large datasets and ORDER BY/LIMIT queries:
1. `maybeRunGraph` while loop (collection-config-builder.ts):
- Can loop infinitely when data loading triggers graph updates
- Happens when WHERE filters out most data, causing dataNeeded() > 0
- Loading more data triggers updates that get filtered out
- Added 10,000 iteration limit with error logging
2. `requestLimitedSnapshot` while loop (subscription.ts):
- Can loop if index iteration has issues
- Added 10,000 iteration limit with error logging
- Removed unused `insertedKeys` tracking
3. `D2.run()` while loop (d2.ts):
- Can loop infinitely on circular data flow bugs
- Added 100,000 iteration limit with error logging
The safeguards log errors to help debug the root cause while
preventing the app from freezing.1 parent 05130f2 commit d8f95da
File tree
3 files changed
+51
-2
lines changed- packages
- db-ivm/src
- db/src
- collection
- query/live
3 files changed
+51
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
60 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
63 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
505 | 512 | | |
506 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
507 | 522 | | |
508 | 523 | | |
509 | 524 | | |
| |||
515 | 530 | | |
516 | 531 | | |
517 | 532 | | |
518 | | - | |
519 | 533 | | |
520 | 534 | | |
521 | 535 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
339 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
340 | 360 | | |
341 | 361 | | |
342 | 362 | | |
| |||
0 commit comments