Repository navigation
Fix spurious "TLS/SSL error: Interrupted system call" from MySQL client reads - #120526
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings) plus my own cold review
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260917-064400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260917-052700 |
|
Workflow [PR], commit [06506cb] Summary: ✅
AI ReviewSummaryThis PR bumps PR Metadata
Exact replacement: ### Changelog category (leave one):
- Bug FixFindings💡 Nits
Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 06506cb.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +130 lines in 37 files (-188 lines lost coverage) · Details |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 4 s compile time in total, 7 of them have a recent master baseline. |
ce7b5e0 to
291e302
Compare
|
I corrected the changelog category to 26.7 and 26.8 pin the defective commit, so this still needs a backport. Merge order also matters here: ClickHouse/mariadb-connector-c#25 carries the actual code change and has to land first, and a squash or rebase merge there changes |
…nt reads Bump contrib/mariadb-connector-c to pick up a single connector change: ERR_clear_error() before every SSL_connect/SSL_read/SSL_write whose result is interpreted through SSL_get_error(), plus capturing errno as the first statement of ma_tls_set_error(). SSL_get_error() only reports the retry flags of the operation just attempted while the calling thread's OpenSSL error queue is empty, and openssl.c never cleared it. A leftover ERR_LIB_SYS entry from any earlier OpenSSL operation on the same thread is therefore reported first (ossl_ssl_get_error() returns SSL_ERROR_SYSCALL for ERR_LIB_SYS before it looks at SSL_want_read() and the BIO retry flag), so a read that OpenSSL had already marked retryable becomes fatal. ma_tls_set_error() then pops the stale entry, gets NULL from ERR_reason_error_string() and prints strerror_r(errno) instead, producing mysqlxx::BadQuery: TLS/SSL error: Interrupted system call (4) on a healthy connection, with an errno that need not belong to the failing call. Every mysql() table function, MySQL table/database engine and MySQL dictionary read is affected: mysqlxx::Connection::connect enables TLS unconditionally via mysql_ssl_set, the sampling query profiler is on by default so query threads take periodic signals, and the TLS path bypasses ma_recv()'s EINTR retry loop because OPENSSL_USE_BIOMETHOD is undefined and SSL_set_fd() lets OpenSSL read the socket directly. No regression test ships with this. With an empty error queue the message is unreachable on the old pin: sock_read() zeroes errno before every recv, EINTR is classified retryable, and pvio_socket_wait_io_or_timeout() re-polls it against its deadline and reports ETIMEDOUT. 428000 instrumented un-injected reads produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry was found, so the failing arm of a functional test would be unobservable. The fix was validated by forcing a stale entry on the reading thread instead: 20 of 20 reads and 2-3 of 20 02479_mysql_connect_to_self runs failed before it, 20 of 20 and 50 of 50 passed after, and 125319 stale entries were still measured at SSL entry on the green arm, so that arm is not vacuous. The changelog category is the one the fix-carrying contrib bumps use (usearch ClickHouse#118828, openssl ClickHouse#118927) rather than Bug Fix: the change in this repository is only the dependency pin, and the Bug Fix category's validation expects a regression test that reddens on master, which this defect cannot supply. Connector change: ClickHouse/mariadb-connector-c#25 Related: ClickHouse#105987
| @@ -1 +1 @@ | |||
| Subproject commit 111ec1a5958cf984f50a28b0fb82a4087918d677 | |||
| Subproject commit a5abc0b46c34df6274e65eb9c50d53733a2b3385 | |||
There was a problem hiding this comment.
Attaching this to the gitlink because it is the only changed line: the Changelog category looks semantically wrong here. This pin fixes stable user-visible runtime failures in mysql(), the MySQL table and database engines, and MySQL dictionaries, so it matches Bug Fix, not Build/Testing/Packaging Improvement, even though the implementation arrives via a submodule update.
There was a problem hiding this comment.
The runtime effect is user-visible, agreed: on 26.7 and 26.8 this shows up as a spurious TLS/SSL error: Interrupted system call from mysql(), the MySQL table and database engines and MySQL dictionaries. I did not pick the category on visibility alone, because pr-bugfix also commits this PR to a contract it cannot satisfy.
new_tests_check.py makes pr-bugfix merge-blocking unless the diff adds a test, and for a functional or integration test it further requires at least one per-arch Bugfix validation job to report OK or XFAIL, i.e. the test has to fail on master HEAD. That arm is unobservable here: with an empty OpenSSL error queue this message is unreachable on the old pin, 428000 instrumented un-injected reads produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry exists. The gate already fired on ce7b5e0 and took Mergeable Check with it.
Merged contrib bumps split on exactly that line. #117422 is the recent pr-bugfix one, and it could ship 05104_uniq_theta_compressed_state.sql because its defect was reachable from SQL. The fix-carrying bumps that could not ship a test merged as #118828 Not for changelog, #118927 Build/Testing/Packaging Improvement and #119262 Improvement, with no category objection raised on any of the three. The entry itself is not lost either: pr-build is not in NO_CHANGELOG_REQUIRED_LABELS, so the user-facing text still goes into CHANGELOG.md.
If a maintainer prefers Bug Fix, the honest way to earn it is a test-only injection point in the client read path so a gtest can force the stale entry. I will add that on request rather than on my own judgement.
291e302 to
06506cb
Compare
Related: #105987
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Bumped
mariadb-connector-cto clear the OpenSSL error queue before every TLS operation. This removes spuriousTLS/SSL error: Interrupted system callfailures ofmysql(), theMySQLtable and database engines and MySQL dictionaries, where a leftover queue entry made a signal-interrupted read fatal.Description
mysqlxxconnections always use TLS and the query profiler is on by default, so their blocking TLS reads take periodic signals. OpenSSL marksEINTRretryable through the BIO retry flag, butSSL_get_error()reports those flags only while the calling thread's error queue is empty, andlibmariadb/secure/openssl.cnever cleared it:ossl_ssl_get_error()checksERR_peek_error()first and returnsSSL_ERROR_SYSCALLfor anyERR_LIB_SYSentry before the retry flag. A leftover entry from an earlier operation on the same thread therefore makesma_tls_read()treat a retryable read as fatal and reportstrerror_r(errno).ma_recv()'sEINTRloop is not on this path: OpenSSL reads the socket directly.This bumps
contrib/mariadb-connector-cto branchfix-tls-clear-openssl-error-queue:ERR_clear_error()before everySSL_connect/SSL_read/SSL_writeread throughSSL_get_error(), anderrnocaptured first inma_tls_set_error(). Same convention assrc/IO/SocketPeerClosed.cpp.I could not identify what left the entry behind, but with an empty queue this message is unreachable on the old pin:
sock_read()zeroeserrnobefore everyrecv,EINTRis retryable, andpvio_socket_wait_io_or_timeout()re-polls it and reportsETIMEDOUT(#109592).Validation: with a stale
ERR_LIB_SYSentry forced on the reading thread, 20 of 20 reads and 2-3 of 2002479_mysql_connect_to_selfruns failed as above; with the fix, 20 of 20 and 50 of 50 are green while 125319 stale entries were still measured at SSL entry, so the green arm is not vacuous.Un-injected, 428000 instrumented reads produced none and no SQL-reachable producer was found, so no ClickHouse-side regression test is possible; the category is the one the fix-carrying bumps #118828 and #118927 used rather than
Bug Fix. 26.7 and 26.8 pin the defective commit, so this needs a backport.Seen in
Stateless tests (arm_binary, parallel)on9bd06dabfe74(report).#119510 (v3.4.10) does not supersede this: it also lacks the clear, and a stale entry defeats its new
SSL_ERROR_SYSCALL && !ERR_peek_error()EOF shortcut. Forward-ported there onfwd-v3.4.10-tls-clear-openssl-error-queue.Workflow [PR]
Sync PR [sync-upstream/pr/120526]
Version info
26.10.1.165(included in26.10and later)