Commit a735370
committed
fix: prevent race condition in MCP server start
Make singleton enforcement atomic by checking for existing MCP server
inside the register_mcp_serve_process() lock. This prevents two
concurrent start commands from both passing the check and spawning
duplicate processes.
Additional improvements:
- Use std::mem::forget() to document intentional process detachment
- Kill spawned process if registration fails (cleanup on race loss)
- Move singleton check comment from caller to enforcement point1 parent cb8bb77 commit a735370
2 files changed
Lines changed: 44 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
628 | 628 | | |
629 | 629 | | |
630 | 630 | | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | 631 | | |
640 | 632 | | |
641 | 633 | | |
| |||
647 | 639 | | |
648 | 640 | | |
649 | 641 | | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
654 | 645 | | |
655 | | - | |
656 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
657 | 670 | | |
658 | 671 | | |
659 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
161 | | - | |
| 160 | + | |
162 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
163 | 178 | | |
164 | 179 | | |
165 | 180 | | |
| |||
172 | 187 | | |
173 | 188 | | |
174 | 189 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 190 | | |
179 | 191 | | |
180 | 192 | | |
| |||
0 commit comments