Skip to content

ZOOKEEPER-5120: (C client) Forced close leaks request queues and corrupts session state - #2495

Open
apurtell wants to merge 1 commit into
apache:masterfrom
apurtell:ZOOKEEPER-5120
Open

apurtell wants to merge 1 commit into
apache:masterfrom
apurtell:ZOOKEEPER-5120

Conversation

@apurtell

@apurtell apurtell commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Calling threads close the client socket directly during server reconfigurations or failed async writes, bypassing proper cleanup and producing invalid internal states. This triggers several race conditions: healthy connections are dropped when the wake-up pipe backs up, pending requests are routed to new servers prematurely, watchers are exposed to inconsistent states, and authentication failures are masked.

The fix is to manage the lifecycle strictly in the I/O driver. Calling threads no longer close sockets or mutate client state themselves. Instead they set a disconnect request flag and signal the I/O thread. The driver handles the teardown deterministically, notifying watchers of a reconnecting state, cleanly failing in-flight requests with connection loss, and hardening the wake up path against pipe congestion and signal interruptions.

Add Zookeeper_operations tests testServerListChangeFailsPendingRequests, testSendFailureDefersTeardown, testPingSendFailureTearsDown, testServerListChangeKeepsAuthFailedState (ST),
testServerListChangeDuringSessionEstablishment and testFullWakeupPipeKeepsConnection (MT).

…rupts session state

Calling threads close the client socket directly during server
reconfigurations or failed async writes, bypassing proper cleanup and
producing invalid internal states. This triggers several race conditions:
healthy connections are dropped when the wake-up pipe backs up, pending
requests are routed to new servers prematurely, watchers are exposed to
inconsistent states, and authentication failures are masked.

The fix is to manage the lifecycle strictly in the I/O driver. Calling
threads no longer close sockets or mutate client state themselves. Instead
they set a disconnect request flag and signal the I/O thread. The driver
handles the teardown deterministically, notifying watchers of a
reconnecting state, cleanly failing in-flight requests with connection
loss, and hardening the wake up path against pipe congestion and signal
interruptions.

Add Zookeeper_operations tests testServerListChangeFailsPendingRequests,
testSendFailureDefersTeardown, testPingSendFailureTearsDown,
testServerListChangeKeepsAuthFailedState (ST),
testServerListChangeDuringSessionEstablishment and
testFullWakeupPipeKeepsConnection (MT).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apurtell apurtell changed the title ZOOKEEPER-5120: (C client) Forced closes leaks request queues and corrupts session state ZOOKEEPER-5120: (C client) Forced close leaks request queues and corrupts session state Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant