Skip to content

Do not log benign ENOTCONN on socket shutdown during ZooKeeper finalize - #107438

Merged
CheSema merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-keeper-client-shutdown-enotconn-stderr
Jul 7, 2026
Merged

CheSema merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-keeper-client-shutdown-enotconn-stderr

Conversation

@groeneai

@groeneai groeneai commented Jun 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #100651

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Stop logging a benign Net Exception: Socket is not connected error during ZooKeeper session finalize on macOS. clickhouse keeper-client no longer prints this spurious error to stderr at exit.

Description

On macOS, shutdown() on an already-disconnected socket returns ENOTCONN (errno 57). Poco::Net::SocketImpl::shutdown() converts any non-zero return into NetException("Socket is not connected"). In Coordination::ZooKeeper::finalize() the socket.shutdown() call is wrapped in try/catch and logged via tryLogCurrentException(log), which defaults to ERROR. keeper-client in query mode sends ERROR logs to stderr, so at process exit this benign teardown noise lands on stderr.

This is what makes the keeper-client Fast test (arm_darwin) tests fail intermittently (03135_keeper_client_find_commands, 03230_keeper_cp_mv_commands, 03231_keeper_cpr_mvr_commands, 03988_keeper_client_autocomplete): the command output is correct, but the test harness treats any stderr as a failure. It is a low-frequency, macOS-only flaky across unrelated PRs (0 master failures).

This downgrades the ENOTCONN case to TRACE at both socket.shutdown() catch sites (finalize teardown and the connect-failure cleanup path), keeping ERROR for all other shutdown errors. It mirrors the existing precedent in HTTPServerConnection.cpp, which already checks e.code() == POCO_ENOTCONN and logs at a lower level.

Reported by alexey-milovidov in #100651. arm_darwin is macOS, so the ENOTCONN path does not reproduce on the Linux build box; the change is backed by the CI report stack traces and an in-tree precedent. Verified on Linux that the normal keeper-client teardown path produces no stderr (no regression).

CI report (Fast test (arm_darwin), PR #100651): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100651&sha=5370da39b454d590a5639759af8d993f1f5b4663&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29

Version info

  • Merged into: 26.7.1.581 (included in 26.7 and later)

On macOS, calling shutdown() on an already-disconnected socket returns
ENOTCONN (errno 57). Poco::Net::SocketImpl::shutdown() turns any non-zero
return into a NetException("Socket is not connected"). In
Coordination::ZooKeeper::finalize() the socket.shutdown() call is wrapped in
try/catch and the exception is logged via tryLogCurrentException(log), which
defaults to ERROR level. keeper-client in query mode sends ERROR logs to
stderr, so at process exit this benign teardown noise lands on stderr.

This makes the stateless test 03135_keeper_client_find_commands fail on
Fast test (arm_darwin) only: the command output is correct, but the test
harness treats any stderr ("having stderror") as a failure. It is a low
frequency, macOS-only flaky across unrelated PRs (0 master failures).

Downgrade the ENOTCONN case to TRACE at both socket.shutdown() catch sites
(finalize teardown and the connect-failure cleanup path), keeping ERROR for
all other shutdown errors. This mirrors the existing precedent in
HTTPServerConnection.cpp, which already checks e.code() == POCO_ENOTCONN and
logs at a lower level to avoid spamming logs with benign disconnect noise.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Partial. arm_darwin is macOS; the ENOTCONN-on-shutdown() path does not occur on Linux, so the stderr cannot be reproduced on the Linux build box. The trigger is deterministic and fully understood from the CI evidence: on macOS, shutdown() on an already-disconnected socket returns ENOTCONN (errno 57). Three Fast test (arm_darwin) CI reports (PRs #100651, #101216, #95657) show the identical stack Poco::Net::SocketImpl::shutdown -> Coordination::ZooKeeper::finalize -> ~ZooKeeper -> KeeperClient::main, with correct stdout and 0 master failures.
b Root cause explained? Poco::Net::SocketImpl::shutdown() converts any non-zero ::shutdown() return into NetException("Socket is not connected", ENOTCONN). Coordination::ZooKeeper::finalize() catches it and logs via tryLogCurrentException(log), which defaults to LogsLevel::error. keeper-client in query mode routes ERROR logs to stderr. The Fast-test harness fails any test that emits stderr ("having stderror"), so the benign teardown error fails the test even though the command output is correct.
c Fix matches root cause? Yes. The fix catches Poco::Net::NetException at the exact socket.shutdown() catch site from the stack and downgrades only e.code() == POCO_ENOTCONN to TRACE; every other shutdown error still logs at ERROR via the existing path. It addresses the mechanism (benign ENOTCONN logged at ERROR -> stderr), not a symptom.
d Test intent preserved / new tests added? N/A. No test was modified. The existing 03135_keeper_client_find_commands still validates keeper-client output; it simply no longer sees spurious teardown stderr. A new regression test is not feasible because it would require a macOS runner to exercise the ENOTCONN path.
e Both directions demonstrated? Partial. The fix direction (ENOTCONN suppressed) cannot be shown on Linux since the path does not fire there. The no-regression direction is shown: built the binary (Build ID a194bd38...), ran the full test's keeper-client command sequence against a local keeper, confirmed stdout matches the reference exactly and stderr is empty.
f Fix is general, not a narrow patch? Yes. Both socket.shutdown() catch sites in ZooKeeperImpl.cpp (finalize teardown and the connect-failure cleanup path) carry the identical benign-shutdown pattern; both were fixed. Fixing at the ClickHouse caller (not in vendored Poco, whose throw is correct in general) matches the existing in-tree precedent HTTPServerConnection.cpp, which downgrades POCO_ENOTCONN the same way.

Session id: cron:clickhouse-worker-slot-2:20260614-072200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antonio2368 @alesapin could you review this? It downgrades the benign macOS ENOTCONN error from socket.shutdown() in Coordination::ZooKeeper::finalize() from ERROR to TRACE (keeping ERROR for all other shutdown errors), so keeper-client stops emitting spurious teardown stderr that fails 03135_keeper_client_find_commands on Fast test (arm_darwin). Mirrors the existing POCO_ENOTCONN downgrade in HTTPServerConnection.cpp.

@clickhouse-gh

clickhouse-gh Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [69afd49]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) FAIL
Logical error: Block structure mismatch in A stream: different columns: (STID: 0993-27f0) FAIL cidb

AI Review

Summary

This PR narrows ZooKeeper shutdown logging by treating POCO_ENOTCONN from socket.shutdown as benign teardown noise at the two existing cleanup/finalization catch sites, while preserving ERROR logging for all other shutdown failures. I did not find a code-level correctness, safety, or performance issue; no inline review comments were posted.

PR Metadata
  • Changelog category Bug Fix (user-visible misbehavior in an official stable release) is appropriate for the macOS clickhouse keeper-client stderr noise described by the PR.
  • The required changelog entry is specific and user-readable.
  • 💡 The relationship line in the PR body uses Related: #100651, but the repository instructions ask for full GitHub URLs. Replace it with Related: https://github.com/ClickHouse/ClickHouse/pull/100651.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on ee14923. Disposition of the only red:

The target test of this PR, 03135_keeper_client_find_commands, passed on Fast test (arm_darwin) and every other variant on this commit. All other jobs are green.

@alesapin alesapin self-assigned this Jun 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.20% -0.10%
Functions 92.60% 92.50% -0.10%
Branches 77.50% 77.40% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 6/14 (42.86%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 8 line(s) · Uncovered code

Full report · Diff report

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 69afd49

CI fully finished (Finish Workflow pass). The sole failure is a chronic trunk AST-fuzzer logical error, unrelated to this ZooKeeper-finalize logging change.

Check / test Reason Owner / fixing PR
AST fuzzer (amd_debug) / "Block structure mismatch in stream" (STID 0993-27f0) crash (chronic trunk AST-fuzzer UnionStep/IntersectOrExcept bug: 142 PRs, 13 master/30d) #107719 (ours, open)

Session id: cron:our-pr-ci-monitor:20260703-053000

@CheSema
CheSema added this pull request to the merge queue Jul 7, 2026
Merged via the queue into ClickHouse:master with commit 695b499 Jul 7, 2026
165 of 167 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 7, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…shutdown-enotconn-stderr

Do not log benign ENOTCONN on socket shutdown during ZooKeeper finalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants