Commit 4340371
committed
fix(qwp): failed-stop teardown protocol -- never free the engine or client under a live I/O thread (C5 SEGV)
Completes the C5 fix. The landed discard-when-stopped commit removed the
routine post-teardown engine access; this eliminates the SEGV class on
the close path by construction: every native free is either ordered
after the I/O thread's last access via the shutdown latch, or performed
by the I/O thread itself.
1. CursorWebSocketSendLoop.close(): an interrupted latch await with the
thread still live (latch count nonzero) now re-asserts the interrupt
and THROWS instead of falling through -- falling through both closed
the client's native buffers under a possibly mid-send thread and let
owners unmap the engine under it. A concurrent latch-zero race is
detected and proceeds as a normal stop. ioThread stays set on the
throw, so a duplicate close() re-signals rather than silently
succeeding.
2. delegateEngineClose() + delegated close in ioLoop's finally: on a
failed stop the owner hands engine.close() to the I/O thread's exit
path, which runs it strictly after the thread's last engine access
and after the latch countdown. Store/load handshake (flag write then
latch read vs countdown then flag read) guarantees no missed close
under volatile SC; engine.close() is synchronized and idempotent, so
a double close from both sides is benign. Unlike a deliberate leak,
this releases the mapping and slot lock as soon as the stuck wire
call resolves (bounded by OS timeouts) -- deferred, never abandoned.
3. BackgroundDrainer.run() finally: on a failed loop stop, skip the
client close (the thread may be mid-send on it; its exit path closes
the loop's current client) and delegate the engine close, falling
back to closing locally when the thread exited in the interim. The
mid-drain capability-gap recycle bails out on a failed stop instead
of opening a new wire session against an engine the old thread still
uses; the finally re-signals and applies the same protocol.
4. QwpWebSocketSender.close(): the ioThreadStopped guard -- now actually
armed by close()'s throw, which the swallow previously made
unreachable -- keeps leaking the microbatch buffers and client
deliberately, but delegates the owned engine close instead of
leaking the mapping and slot flock forever. slotLockReleased stays
false: the pool must not reuse the slot until the delegated close
has actually run.
Turns BackgroundDrainerInterruptedTeardownTest green; the C5 leak test
and close tests stay green. Regression net: sf/cursor + qwp/client +
impl + http/client (1249) and the sf integration package (incl.
BackgroundDrainerEndToEndTest, OrphanScanIntegrationTest) -- all green.
Residual analysis: with the connect racing close(), a client obtained
after running flips false is discarded on the I/O thread; a swapClient
already in flight completes against an engine that is now guaranteed
still mapped (owners cannot unmap while the latch is up and the thread
is live). No close-path free can race the I/O thread anymore.1 parent c7419f4 commit 4340371
3 files changed
Lines changed: 143 additions & 8 deletions
File tree
- core/src/main/java/io/questdb/client/cutlass/qwp/client
- sf/cursor
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1062 | 1062 | | |
1063 | 1063 | | |
1064 | 1064 | | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
1065 | 1086 | | |
1066 | 1087 | | |
1067 | 1088 | | |
| |||
Lines changed: 49 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
538 | 552 | | |
539 | 553 | | |
540 | 554 | | |
| |||
584 | 598 | | |
585 | 599 | | |
586 | 600 | | |
| 601 | + | |
587 | 602 | | |
588 | 603 | | |
589 | 604 | | |
590 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
591 | 617 | | |
592 | 618 | | |
593 | | - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
594 | 624 | | |
595 | 625 | | |
596 | 626 | | |
597 | 627 | | |
598 | 628 | | |
599 | 629 | | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
604 | 646 | | |
605 | 647 | | |
606 | 648 | | |
| |||
Lines changed: 73 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
220 | 226 | | |
221 | 227 | | |
222 | 228 | | |
| |||
576 | 582 | | |
577 | 583 | | |
578 | 584 | | |
579 | | - | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
580 | 600 | | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
581 | 610 | | |
582 | 611 | | |
583 | 612 | | |
| |||
602 | 631 | | |
603 | 632 | | |
604 | 633 | | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
605 | 662 | | |
606 | 663 | | |
607 | 664 | | |
| |||
1232 | 1289 | | |
1233 | 1290 | | |
1234 | 1291 | | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
1235 | 1307 | | |
1236 | 1308 | | |
1237 | 1309 | | |
| |||
0 commit comments