Commit e5bfe3b
committed
fix: Resolve critical bugs in concurrency, memory safety, and thread handling
This commit addresses 24 issues including critical bugs that could cause crashes,
memory leaks, race conditions, and data corruption in production.
Critical Priority Fixes:
- Buffer overflow in result_sorter.cpp (snprintf buffer size)
- Null pointer crash in connection.cpp (ValidateUniqueColumn)
- GTID race condition in binlog_reader.cpp (atomic operations with RAII guard)
High Priority Fixes:
- running_ flag race in invalidation_queue.cpp (compare_exchange_strong)
- Cache invalidation incomplete in http_server.cpp (empty_ngrams to actual ngrams)
- is_optimizing_ race in index.cpp (confirmed already safe)
Medium Priority Fixes:
- Task queue race in thread_pool.cpp (confirmed already safe)
- Thread management race in sync_operation_manager.cpp (unified mutex)
- Key accumulation in invalidation_queue.cpp (always update timestamp)
- Readline memory leak in mygram-cli.cpp (RAII pattern)
- Thread leak on exception in binlog_reader.cpp (explicit reset)
Low Priority Fixes:
- Parameter naming inconsistency in invalidation_queue.cpp
- Unused method declaration in binlog_reader.h
- Duplicate Cancel calls in sync_operation_manager.cpp
- Thread start race in http_server.cpp
- Boundary check insufficient in document_store.cpp
- Exponential backoff unbounded in binlog_reader.cpp
- Single-table mode inconsistency in binlog_reader.cpp
- const reference lifetime documentation in invalidation_queue.h
- Ownership inconsistency documentation in binlog_reader.h
- Statistics duplication in http_server.cpp
Confirmed Already Implemented:
- UPDATE index handling in binlog_reader.cpp
- const correctness in index.cpp
Additional Critical Fix (Discovered During Testing):
- CRITICAL: Dangling pointer in Index::Optimize() causing SEGFAULT
Problem: Snapshot used raw PostingList* pointers, causing dangling pointers
when other threads deleted term_postings_ entries after lock release
Solution: Implemented RCU (Read-Copy-Update) pattern with 3-phase optimization
- Phase 1a: Copy shared_ptrs (instant, shared_lock)
- Phase 1b: Clone posting lists (CPU-intensive, NO LOCK for full concurrency)
- Phase 2: Atomic swap for existing terms only (instant, unique_lock)
Changed unique_ptr to shared_ptr for reference counting
- Maximizes concurrency: searches never blocked, writes minimally blocked
- Preserves concurrent modifications: deleted terms not re-added
- Tests: Enhanced OptimizeThreadSafety, new OptimizeDanglingPointerRegression
- All 880 tests passing
Summary:
- Total fixes: 24 issues (21 fixed + 2 confirmed + 1 additional critical)
- New tests added: 14
- Affected components: Cache, MySQL, Index, Server, Storage, CLI1 parent 14c5492 commit e5bfe3b
File tree
23 files changed
+935
-167
lines changed- src
- cache
- cli
- index
- mysql
- query
- server
- storage
- tests
- cache
- index
- mysql
- server
- storage
23 files changed
+935
-167
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
39 | 47 | | |
40 | 48 | | |
41 | 49 | | |
| |||
45 | 53 | | |
46 | 54 | | |
47 | 55 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
53 | 65 | | |
54 | 66 | | |
55 | | - | |
56 | | - | |
| 67 | + | |
| 68 | + | |
57 | 69 | | |
58 | 70 | | |
59 | 71 | | |
| |||
66 | 78 | | |
67 | 79 | | |
68 | 80 | | |
69 | | - | |
| 81 | + | |
70 | 82 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
86 | 92 | | |
87 | 93 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
94 | 97 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 98 | + | |
| 99 | + | |
101 | 100 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 101 | + | |
| 102 | + | |
107 | 103 | | |
108 | 104 | | |
109 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 67 | + | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
72 | 71 | | |
73 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
74 | 78 | | |
75 | 79 | | |
76 | 80 | | |
77 | | - | |
78 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
87 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
88 | 95 | | |
89 | 96 | | |
90 | | - | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
215 | 221 | | |
216 | 222 | | |
217 | 223 | | |
218 | | - | |
219 | | - | |
| 224 | + | |
| 225 | + | |
220 | 226 | | |
221 | 227 | | |
222 | 228 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | | - | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
533 | | - | |
| 533 | + | |
| 534 | + | |
534 | 535 | | |
535 | | - | |
| 536 | + | |
536 | 537 | | |
537 | 538 | | |
538 | 539 | | |
539 | 540 | | |
540 | 541 | | |
541 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
542 | 547 | | |
543 | 548 | | |
544 | 549 | | |
| |||
549 | 554 | | |
550 | 555 | | |
551 | 556 | | |
552 | | - | |
| 557 | + | |
553 | 558 | | |
554 | | - | |
555 | | - | |
556 | | - | |
| 559 | + | |
557 | 560 | | |
558 | 561 | | |
559 | 562 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
465 | | - | |
466 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
467 | 468 | | |
468 | 469 | | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
473 | 481 | | |
474 | 482 | | |
475 | | - | |
476 | | - | |
477 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
478 | 503 | | |
479 | 504 | | |
480 | 505 | | |
481 | 506 | | |
482 | | - | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
483 | 514 | | |
484 | 515 | | |
485 | 516 | | |
| |||
527 | 558 | | |
528 | 559 | | |
529 | 560 | | |
530 | | - | |
| 561 | + | |
531 | 562 | | |
532 | 563 | | |
533 | 564 | | |
| |||
598 | 629 | | |
599 | 630 | | |
600 | 631 | | |
601 | | - | |
| 632 | + | |
602 | 633 | | |
603 | 634 | | |
604 | 635 | | |
| |||
782 | 813 | | |
783 | 814 | | |
784 | 815 | | |
785 | | - | |
| 816 | + | |
786 | 817 | | |
787 | 818 | | |
788 | 819 | | |
| |||
804 | 835 | | |
805 | 836 | | |
806 | 837 | | |
807 | | - | |
| 838 | + | |
808 | 839 | | |
809 | 840 | | |
810 | 841 | | |
| |||
867 | 898 | | |
868 | 899 | | |
869 | 900 | | |
870 | | - | |
| 901 | + | |
871 | 902 | | |
872 | 903 | | |
873 | 904 | | |
| |||
889 | 920 | | |
890 | 921 | | |
891 | 922 | | |
892 | | - | |
| 923 | + | |
893 | 924 | | |
894 | 925 | | |
895 | 926 | | |
| |||
0 commit comments