Commit acb32b9
fix(ilp): plug SF rotate-OOM double-free and on-disk leak
SegmentLog.rotate freed old.pathPtrNative and assigned the new sealed-
path pointer in non-atomic order: free → assign-path → alloc → set
sealed. If allocNativePath OOMed mid-sequence the segment was left in
two simultaneously broken states:
- pathPtrNative still held the freed pointer (the assignment never
ran). On close() the segments-cleanup loop called freeNativePath
on it again — a native-heap double-free that crashed the JVM with
malloc free-list corruption (verified via the new red test on the
unfixed code: surefire reported "The forked VM terminated without
properly saying goodbye").
- sealed/lastSeqOnDisk were never set, so trim()'s !s.sealed guard
silently skipped the segment. The .sfs file on disk was never
reclaimed within the lifetime of the process.
Fix:
- Set old.pathPtrNative=0 immediately after the free so a subsequent
OOM cannot leave a stale freed pointer in the field.
- Mark sealed=true / lastSeqOnDisk=lastSeq BEFORE allocating the new
pointer. After OOM the segment is still classified as sealed so
trim can reclaim it.
- trim() now handles the recovery case where pathPtrNative is 0 by
falling back to ff.remove(path) (one-time per trim, acceptable —
these recovery branches only fire after an OOM, not on the hot
path).
Test: testRotateOomLeavesSegmentInRecoverableSealedState
(SegmentLogTest). Forces rotation under an injected allocNativePath
OOM, then asserts (a) close() does not double-free, (b) trim() reaps
the orphan .sfs file. On the unfixed code the JVM dies; on the fix
118 SF + adjacent tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 86b6e6f commit acb32b9
2 files changed
Lines changed: 136 additions & 6 deletions
File tree
- core/src
- main/java/io/questdb/client/cutlass/qwp/client/sf
- test/java/io/questdb/client/test/cutlass/qwp/client/sf
Lines changed: 21 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
278 | | - | |
279 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
280 | 287 | | |
281 | 288 | | |
282 | 289 | | |
| |||
561 | 568 | | |
562 | 569 | | |
563 | 570 | | |
564 | | - | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
565 | 580 | | |
| 581 | + | |
566 | 582 | | |
567 | | - | |
568 | 583 | | |
569 | 584 | | |
| 585 | + | |
570 | 586 | | |
571 | 587 | | |
572 | 588 | | |
| |||
Lines changed: 115 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
637 | 637 | | |
638 | 638 | | |
639 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
640 | 743 | | |
641 | 744 | | |
642 | 745 | | |
| |||
1024 | 1127 | | |
1025 | 1128 | | |
1026 | 1129 | | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1027 | 1135 | | |
1028 | 1136 | | |
1029 | 1137 | | |
1030 | | - | |
| 1138 | + | |
| 1139 | + | |
1031 | 1140 | | |
1032 | 1141 | | |
1033 | 1142 | | |
1034 | 1143 | | |
1035 | 1144 | | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
1036 | 1150 | | |
1037 | 1151 | | |
1038 | 1152 | | |
| |||
0 commit comments