42 Commits
Author SHA1 Message Date
Alexey MilovidovandClaude Opus 4.8 6c72e9a563 Detect HTTP keep-alive peer disconnect with MSG_PEEK/SSL_peek, not poll
`HTTPConnectionPool::isStale` decided whether a pooled keep-alive
connection was still usable with `poll(SELECT_READ, 0)`: readable meant
stale, on the assumption that an idle keep-alive connection has no data
pending. On a plain socket that holds, but on an HTTPS connection it
produces a false positive. `poll` reflects the raw TCP socket, so an
unread TLS post-handshake record (a session ticket or `KeyUpdate`) makes
an entirely live secure connection look readable, i.e. stale, and the
pool discards it and reconnects - at the cost of a fresh TLS handshake -
on nearly every borrow.

This ports the shared, TLS-aware helper `isSocketPeerClosed` (added in
`src/IO`) from the distributed cache fix and switches
`HTTPConnectionPool::isStale` to it:

- for a plain socket, a single non-blocking, non-destructive
  `recv(..., MSG_PEEK | MSG_DONTWAIT)`: `0` means the peer sent a FIN
  (closed); `> 0` means bytes are on the wire (alive); `EAGAIN` /
  `EWOULDBLOCK` means a healthy idle connection; any other error (e.g.
  `ECONNRESET`) is treated as closed/broken;
- for a TLS (`SecureStreamSocket`) socket, an `SSL_peek` on a temporarily
  non-blocking socket. A raw `MSG_PEEK` cannot tell TLS records apart -
  an unread `close_notify` looks the same as unread application data or a
  session ticket, and in TLS 1.3 the record content type is encrypted.
  `SSL_peek` decrypts just enough to distinguish real application data and
  harmless post-handshake messages (a session ticket or `KeyUpdate`),
  treated as alive, from a `close_notify` (`SSL_ERROR_ZERO_RETURN`) or a
  broken session, treated as closed, without consuming application data.

A small `ssl` accessor is added to Poco's
`SecureSocketImpl` / `SecureStreamSocketImpl` to reach the underlying
OpenSSL `SSL` object.

`gtest_socket_peer_closed` covers both paths, including a
`socketpair`-backed TLS connection: an unread session ticket and pending
application data read as alive; a `close_notify` and an abrupt close read
as closed. The `close_notify` case also asserts that a raw `MSG_PEEK`
misfires there, which is exactly why the TLS-aware path is needed.

This is the public-repo counterpart, and the follow-up promised in, the
distributed cache fix https://github.com/ClickHouse/clickhouse-private/pull/64217

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-07-14 14:26:39 +00:00
Michael Stetsyuk 159a044b55 do not use std mutex across fiber yield-resume 2026-06-19 17:18:46 +00:00
Michael Stetsyuk cc0f61d614 Reapply "Add silk fibers aware socket implementations"
This reverts commit 4acfc42154.
2026-06-16 14:59:19 +00:00
Raúl MarínandGitHub d419061e26 Revert "Add silk fibers aware socket implementations" 2026-06-15 18:33:11 +02:00
Michael Stetsyuk ea67e13122 proper solution for tls 2026-06-01 21:18:22 +00:00
Michael Stetsyuk b9320787bd Add silk fibers aware socket implementations 2026-05-28 21:39:42 +00:00
Sema ChecherindaandClaude Opus 4.6 5f5e9a50ba fix(Poco): throw TimeoutException on SSL handshake timeout for blocking sockets
completeHandshake had the same issue as sendBytes/receiveBytes:
handleError could return ERR_SSL_WANT_READ (-1) when the timeout was
exhausted, and the negative value leaked to callers silently.

Add the same blocking-socket check. Add a test that connects an SSL
client to a plain TCP server -- the handshake stalls and must throw
instead of returning -1.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-16 18:18:41 +02:00
Sema ChecherindaandClaude Opus 4.6 3ae8ce7b86 fix(Poco): throw TimeoutException when SSL operation times out on blocking socket
SecureSocketImpl::sendBytes and receiveBytes could return negative
ERR_SSL_WANT_READ/ERR_SSL_WANT_WRITE values to callers when the SSL
timeout was exhausted. For blocking sockets this means the operation
timed out, but the error propagated as a silent return code instead of
an exception. Callers like HTTPSession::write did not check for negative
returns from sendBytes, causing the error to reach BufferedStreamBuf
which converted it to ios_base::failure, losing all error context and
bypassing S3 retry logic.

Throw TimeoutException for blocking sockets when handleError returns
a negative value. Non-blocking callers still receive the return codes
they expect.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-16 17:50:05 +02:00
Konstantin Bogdanov d2e70e032c Cleanup 2025-11-12 16:42:05 +01:00
Konstantin Bogdanov e05982e0d4 temp-commit 2025-11-12 16:42:01 +01:00
Konstantin Bogdanov f9967e78cc Update files list 2025-10-21 18:11:57 +02:00
serxa 5a740d5b7b fix secure sockets throttling and fix connection pool integration 2025-07-23 18:14:33 +00:00
serxa 29d7544f7b S3 read and write use socket-level throttling 2025-06-13 18:51:36 +00:00
Konstantin BogdanovandGitHub 02884b7149 Revert "Backport Poco fix for concurrent SecureStreamSocket access" 2025-05-14 21:33:23 +02:00
Konstantin Bogdanov 284e8c22b4 Backport fix 2025-04-22 03:24:34 +02:00
Konstantin Bogdanov a71839349a PoC 2025-04-14 01:07:00 +02:00
Konstantin Bogdanov 66e818caf9 Lint 2025-04-10 21:33:00 +02:00
Konstantin Bogdanov ce5f25e698 Modernize OpenSSL 2025-04-10 21:32:59 +02:00
Konstantin Bogdanov d6886097d9 Remove Poco::Crypto 2025-04-10 21:32:57 +02:00
Konstantin Bogdanov a9f4f14491 Own cryptoprimitives 2025-04-10 21:32:57 +02:00
Konstantin Bogdanov fca186a691 Remove unused stuff 2025-04-02 17:02:45 +02:00
Todd Yocum 228a25a678 [WIP] Very draft, partially complete bind_host implementation 2025-01-17 14:28:56 -05:00
Antonio Andelic 3c47f3df4b Support more advanced SSL options for Keeper internal communication 2024-09-13 14:23:01 +02:00
Nikita MikhaylovandGitHub f38f95a144 Update base/poco/NetSSL_OpenSSL/src/SecureSocketImpl.cpp 2024-08-25 14:26:21 +02:00
Yakov OlkhovskiyandGitHub d163880004 process possible SSL error on connection reset 2024-08-25 00:11:31 -04:00
Azat Khuzhin ef24f51789 Fix handling of SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE with zero timeout
Previously if you were using socket without timeout it wasn't able to
handle SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE, and even though sockets
without timeouts is an odd thing (but it is possible - [1]), it still
may be possible somewhere.

  [1]: https://github.com/ClickHouse/ClickHouse/pull/65917

Signed-off-by: Azat Khuzhin <[email protected]>
2024-07-01 19:33:39 +02:00
Sema Checherinda e36a641a80 Merge branch 'master' into protocols-tls-extend-params 2024-06-20 19:02:12 +02:00
Robert Schulze e3818a9794 Re-enable session caching 2024-06-17 12:16:02 +00:00
Anton Ivashkin 983fa64e4f Fix CertificateReloader usage for custom protocols 2024-05-23 17:53:23 +02:00
Anton Ivashkin 92df0f9737 More parameters for tls layer in protocols 2024-05-16 18:34:17 +02:00
Robert Schulze d30b48f54e Disable session caching to work around tsan races 2024-04-08 11:16:06 +00:00
Robert Schulze d8b1275e81 Fix test_dictionaries_all_layouts_separate_sources
Fixes:
    <Information> ReadWriteBufferFromHTTP: Failed to make request to `https://localhost:8889/`. Error: SSL Exception: error:0A000126:SSL routines::unexpected eof while reading. Failed at try 9/10. Will retry with current backoff wait is 10000/10000 ms.

--> https://github.com/openssl/openssl/discussions/22690#discussioncomment-7534909
2024-04-08 11:04:28 +00:00
Kenji Noguchi 17c4abce10 CVE-2016-2183: disable 3DES 2023-08-01 10:44:43 -07:00
Alexey Milovidov 0e88aae9d7 Remove ConsoleCertificateHandler 2023-06-26 04:27:50 +02:00
avogar ef9bae50b9 Fix bugs in Poco, use true non-blocking IO 2023-05-26 23:11:57 +00:00
Robert Schulze 8fc46f6ea1 Remove POCO_DLL 2023-02-15 09:29:37 +00:00
Robert Schulze 144005319d Remove MSVC support from poco 2023-02-14 22:05:27 +00:00
Robert Schulze d3bcfbb2a5 Run clang-format over poco Foundation Mongo Net NetSSL_OpenSSL Util 2023-02-13 09:22:33 +00:00
Robert Schulze 8144c28c3b Fix spelling 2023-02-10 10:49:55 +00:00
Robert Schulze 1838c8912a Fix warnings in poco netssl_openssl 2023-02-08 11:26:36 +00:00
Robert Schulze f002698e09 More fine-granular warning relaxation 2023-02-08 11:21:59 +00:00
Robert SchulzeandGitHub b79ead9c84 Move poco to base/poco/ (#46075)
* Replicate poco into base/poco/

* De-register poco submodule

* Build poco from ClickHouse

* Exclude poco from stylecheck

* Exclude poco from whitespace check

* Exclude poco from typo check

* Remove x bit from sources/headers (the style check complained)

* Exclude poco from duplicate include check

* Fix fasttest

* Remove contrib/poco-cmake/*

* Simplify poco build descriptions

* Remove poco stuff not used by ClickHouse

* Glob poco sources

* Exclude poco from clang-tidy
2023-02-08 12:04:11 +01:00