Commit 5a15a7e
fix(backend): prevent duplicate index jobs from indexedAt race (#1298)
* fix(backend): prevent duplicate index jobs from indexedAt race
onJobCompleted marked the index job COMPLETED in one write, then ran
several git reads (isRepoEmpty, getCommitHashForRefName,
getLatestCommitTimestamp, getLocalDefaultBranch), then updated
repo.indexedAt in a separate write. During the git-read window the job
was already COMPLETED but indexedAt was still stale, so the scheduler
(scheduleIndexJobs) saw no active job and an out-of-date indexedAt and
scheduled a duplicate index job. On large repos the window is long
enough to be hit routinely by the 1s scheduler poll.
Run the git reads first, then write status=COMPLETED and indexedAt
together in a single repoIndexingJob.update (nested repo update). Now
the job stays IN_PROGRESS until the moment indexedAt becomes fresh, so
the scheduler's two guards can never both pass at once.
Fixes SOU-1150
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* docs: add CHANGELOG entry for #1298
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent e668c3f commit 5a15a7e
3 files changed
Lines changed: 56 additions & 49 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
525 | 525 | | |
526 | 526 | | |
527 | 527 | | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
528 | 531 | | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | 532 | | |
534 | 533 | | |
535 | 534 | | |
536 | 535 | | |
537 | 536 | | |
538 | | - | |
| 537 | + | |
539 | 538 | | |
540 | 539 | | |
541 | 540 | | |
| |||
552 | 551 | | |
553 | 552 | | |
554 | 553 | | |
| 554 | + | |
| 555 | + | |
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
558 | 559 | | |
559 | 560 | | |
560 | 561 | | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
571 | 568 | | |
572 | 569 | | |
573 | 570 | | |
| |||
754 | 751 | | |
755 | 752 | | |
756 | 753 | | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | 754 | | |
761 | 755 | | |
762 | 756 | | |
763 | 757 | | |
764 | 758 | | |
| 759 | + | |
765 | 760 | | |
766 | 761 | | |
767 | 762 | | |
| |||
840 | 835 | | |
841 | 836 | | |
842 | 837 | | |
843 | | - | |
| 838 | + | |
844 | 839 | | |
845 | 840 | | |
846 | 841 | | |
847 | 842 | | |
848 | 843 | | |
849 | | - | |
| 844 | + | |
850 | 845 | | |
851 | 846 | | |
852 | 847 | | |
| |||
867 | 862 | | |
868 | 863 | | |
869 | 864 | | |
870 | | - | |
| 865 | + | |
871 | 866 | | |
872 | | - | |
| 867 | + | |
873 | 868 | | |
874 | 869 | | |
875 | 870 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
545 | 545 | | |
546 | 546 | | |
547 | 547 | | |
548 | | - | |
| 548 | + | |
549 | 549 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | 550 | | |
560 | 551 | | |
561 | 552 | | |
562 | 553 | | |
563 | 554 | | |
564 | 555 | | |
| 556 | + | |
| 557 | + | |
565 | 558 | | |
566 | 559 | | |
567 | 560 | | |
| |||
576 | 569 | | |
577 | 570 | | |
578 | 571 | | |
579 | | - | |
580 | | - | |
| 572 | + | |
| 573 | + | |
581 | 574 | | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
596 | 599 | | |
597 | 600 | | |
598 | 601 | | |
599 | 602 | | |
600 | 603 | | |
601 | 604 | | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
602 | 613 | | |
603 | 614 | | |
604 | 615 | | |
| |||
610 | 621 | | |
611 | 622 | | |
612 | 623 | | |
613 | | - | |
| 624 | + | |
614 | 625 | | |
615 | 626 | | |
616 | 627 | | |
| |||
0 commit comments