Commit 5d045cb
committed
fix(pooling): fix race conditions, deadlock, and connection leak in PoolEntry
PoolEntry state transitions had several races between netty IO threads,
the HashedWheelTimer heartbeat worker, and user-facing reconnect calls
that surfaced as ABBA deadlocks, NPEs on inline connect failures, and
leaked connections after a KILL/reconnect cycle in CI.
PoolEntry:
- Synchronize state mutations and mark connectFuture, heartbeatTask,
reconnectTask, lastHeartbeatEvent, isLocked, and isShutdown
volatile/AtomicBoolean for cross-thread visibility.
- Narrow the entry-monitor critical sections to field mutations; call
client.close() and emit() outside the monitor to break the ABBA
deadlock between ConnectionImpl and PoolEntry monitors that hung
DistributingRoundRobinBalancerTest.
- Return the local connect future from internalConnect() so an inline
connect failure cannot leave the caller observing a null
connectFuture after handleConnectError() nulls it for reconnect.
- Keep client.close() in shutdown() on every invocation (closeChannel
is idempotent if already closed) but guard only the
onConnectionClosed emit, so a KILL-then-reconnect cycle cannot
leak the new connection when its auth/ping subsequently fails.
- Serialize connectAfter() reconnect-task scheduling to avoid double
scheduling; add a double-check of connectFuture in internalConnect()
to return the in-flight future instead of starting a new connect.
IProtoClientPoolImpl:
- Synchronize forEach() on connectionPoolLock to avoid CME under
concurrent setGroups().
Tests (BasePoolTest / ConnectionPoolReconnectsTest):
- Wait for box.stat.net().CONNECTIONS.current to stabilise in
getActiveConnectionsCount: the IProto worker updates it
asynchronously, so a single read often lags by 5-15 connections
when 20+ are opened in a burst.
- Collapse the wait-for-stable Lua script to a single line so
tarantool emits one YAML document (SnakeYAML rejects
multi-document streams).
- Wait for the active connection count to reach the expected value
in ConnectionPoolReconnectsTest post-reconnect assertions via a
new waitForActiveConnections() helper.
Verified locally on 3.5.0 and 2.11.8: ConnectionPoolReconnectsTest,
ConnectionPoolTest, ConnectionPoolHeartbeatTest,
DistributingRoundRobinBalancerTest, and unit tests all pass
consistently where they were previously flaky.1 parent c76d799 commit 5d045cb
4 files changed
Lines changed: 115 additions & 32 deletions
File tree
- tarantool-pooling/src
- main/java/io/tarantool/pool
- test/java/io/tarantool/pool/integration
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
527 | | - | |
528 | | - | |
529 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
| |||
Lines changed: 70 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
149 | | - | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | | - | |
| 153 | + | |
153 | 154 | | |
154 | 155 | | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
158 | | - | |
| 159 | + | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
| |||
305 | 315 | | |
306 | 316 | | |
307 | 317 | | |
308 | | - | |
| 318 | + | |
309 | 319 | | |
310 | 320 | | |
311 | 321 | | |
| |||
317 | 327 | | |
318 | 328 | | |
319 | 329 | | |
320 | | - | |
| 330 | + | |
321 | 331 | | |
322 | 332 | | |
323 | 333 | | |
| |||
340 | 350 | | |
341 | 351 | | |
342 | 352 | | |
343 | | - | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
344 | 362 | | |
345 | | - | |
346 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
347 | 367 | | |
348 | 368 | | |
349 | 369 | | |
350 | 370 | | |
351 | 371 | | |
352 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
353 | 375 | | |
354 | 376 | | |
355 | 377 | | |
| |||
410 | 432 | | |
411 | 433 | | |
412 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
413 | 444 | | |
414 | 445 | | |
415 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
416 | 450 | | |
417 | 451 | | |
418 | 452 | | |
419 | 453 | | |
420 | 454 | | |
421 | | - | |
| 455 | + | |
422 | 456 | | |
423 | 457 | | |
424 | 458 | | |
| |||
428 | 462 | | |
429 | 463 | | |
430 | 464 | | |
431 | | - | |
432 | | - | |
433 | | - | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
434 | 469 | | |
435 | 470 | | |
436 | 471 | | |
| |||
462 | 497 | | |
463 | 498 | | |
464 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
465 | 504 | | |
466 | 505 | | |
467 | 506 | | |
| |||
470 | 509 | | |
471 | 510 | | |
472 | 511 | | |
473 | | - | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
474 | 515 | | |
475 | 516 | | |
476 | 517 | | |
| |||
480 | 521 | | |
481 | 522 | | |
482 | 523 | | |
483 | | - | |
484 | | - | |
485 | | - | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
486 | 536 | | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | 537 | | |
491 | 538 | | |
492 | 539 | | |
| |||
658 | 705 | | |
659 | 706 | | |
660 | 707 | | |
661 | | - | |
| 708 | + | |
662 | 709 | | |
663 | 710 | | |
664 | 711 | | |
| |||
Lines changed: 38 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
100 | 112 | | |
101 | 113 | | |
102 | 114 | | |
| |||
106 | 118 | | |
107 | 119 | | |
108 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
109 | 143 | | |
110 | 144 | | |
111 | 145 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
0 commit comments