ClickHouse/src/Server
Azat Khuzhin 4f2a0e8eeb Fix possible issues with MySQL server protocol TLS connections
The problem here is that retries (in SecureSocketImpl.cpp::mustRetry())
relies on non-zero socket timeout, but MySQL handler does not set
timeouts for the socket (like other does), and this leads to a problem
when OpenSSL returns SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE, the
connection will be simply terminated.

I've played with this patch, by hacking the openssl sources:

    diff --git a/crypto/bio/bss_sock.c b/crypto/bio/bss_sock.c
    index 82f7be85ae..a399291ff4 100644
    --- a/crypto/bio/bss_sock.c
    +++ b/crypto/bio/bss_sock.c
    @@ -124,7 +125,18 @@ static int sock_read(BIO *b, char *out, int outl)
                 ret = ktls_read_record(b->num, out, outl);
             else
     # endif
    -            ret = readsocket(b->num, out, outl);
    +        {
    +            /* pthread_kill(pthread_self(), SIGUSR1); */
    +            static int i = 0;
    +            if (!(++i % 2))
    +            {
    +                fprintf(stderr, "sock_read: inject EAGAIN\n");
    +                ret = -1;
    +                errno = EAGAIN;
    +            }
    +            else
    +                ret = readsocket(b->num, out, outl);
    +        }
             BIO_clear_retry_flags(b);
             if (ret <= 0) {
                 if (BIO_sock_should_retry(ret))

And after this patch this succeed without errors:

    ch benchmark -c10 -q "SELECT * FROM mysql('127.0.0.1:9004', system, one, 'default', '', SETTINGS connection_pool_size=1, connect_timeout = 100, connection_wait_timeout = 100)"

Note, that this also fixes the timeouts for plain (non-TLS) connections

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2024-07-01 15:22:33 +02:00
..
grpc_protos Support JWT in clickhouse-client 2024-06-19 04:29:46 +02:00
HTTP fixing HTTPHandler 2024-06-25 23:04:47 +02:00
CertificateReloader.cpp Catch exception in tryLoadImpl 2024-06-19 17:21:25 +02:00
CertificateReloader.h Catch exception in sslContext init 2024-06-18 11:20:50 +02:00
CloudPlacementInfo.cpp remove trash 2024-06-26 02:03:22 +02:00
CloudPlacementInfo.h Move definition to cpp 2024-02-14 12:51:14 +01:00
CMakeLists.txt
GRPCServer.cpp Useless changes 2024-05-10 07:30:40 +02:00
GRPCServer.h Fixed tests 2024-02-09 21:39:36 +03:00
HTTPHandler.cpp fixing HTTPHandler 2024-06-25 23:04:47 +02:00
HTTPHandler.h fixing HTTPHandler 2024-06-25 23:04:47 +02:00
HTTPHandlerFactory.cpp Rollback unnecessary style fixes 2024-06-13 11:21:48 +03:00
HTTPHandlerFactory.h Move StringUtils.h/cpp back to Common/ 2024-05-19 09:39:36 +00:00
HTTPHandlerRequestFilter.h Move StringUtils.h/cpp back to Common/ 2024-05-19 09:39:36 +00:00
HTTPPathHints.cpp Add hints for HTTP handlers 2023-08-10 06:23:20 -04:00
HTTPPathHints.h Refactor IHints 2023-09-10 03:48:12 +00:00
HTTPRequestHandlerFactoryMain.cpp Updated implementation 2024-01-25 14:31:49 +03:00
HTTPRequestHandlerFactoryMain.h Updated implementation 2024-01-25 14:31:49 +03:00
HTTPResponseHeaderWriter.cpp Fix CI failure 2024-06-13 14:16:31 +03:00
HTTPResponseHeaderWriter.h Fix styles 2024-06-13 11:21:48 +03:00
InterserverIOHTTPHandler.cpp Initialize global trace collector for Poco::ThreadPool 2024-06-13 19:20:58 +02:00
InterserverIOHTTPHandler.h Updated implementation 2024-01-25 14:31:49 +03:00
IServer.h
KeeperReadinessHandler.cpp Updated implementation 2024-01-25 14:31:49 +03:00
KeeperReadinessHandler.h Revert "Revert "Use CH Buffer for HTTP out stream, add metrics for interfaces"" 2024-01-03 11:47:15 -05:00
KeeperTCPHandler.cpp Initialize global trace collector for Poco::ThreadPool 2024-06-13 19:20:58 +02:00
KeeperTCPHandler.h Updated implementation 2024-01-25 14:31:49 +03:00
KeeperTCPHandlerFactory.h Updated implementation 2024-01-25 14:31:49 +03:00
MySQLHandler.cpp Fix possible issues with MySQL server protocol TLS connections 2024-07-01 15:22:33 +02:00
MySQLHandler.h Fix for clang-19 2024-03-22 22:12:59 +01:00
MySQLHandlerFactory.cpp Updated implementation 2024-01-25 14:31:49 +03:00
MySQLHandlerFactory.h Updated implementation 2024-01-25 14:31:49 +03:00
NotFoundHandler.cpp Revert "Revert "Use CH Buffer for HTTP out stream, add metrics for interfaces"" 2024-01-03 11:47:15 -05:00
NotFoundHandler.h Fixing more headers 2024-02-29 15:40:30 +00:00
PostgreSQLHandler.cpp Initialize global trace collector for Poco::ThreadPool 2024-06-13 19:20:58 +02:00
PostgreSQLHandler.h Updated implementation 2024-01-25 14:31:49 +03:00
PostgreSQLHandlerFactory.cpp Updated implementation 2024-01-25 14:31:49 +03:00
PostgreSQLHandlerFactory.h Updated implementation 2024-01-25 14:31:49 +03:00
PrometheusMetricsWriter.cpp Reduce header dependencies 2024-03-19 17:04:29 +01:00
PrometheusMetricsWriter.h Send only specific events/metrics for Keeper prometheus 2024-02-13 16:01:50 +01:00
PrometheusRequestHandler.cpp Send only specific events/metrics for Keeper prometheus 2024-02-13 16:01:50 +01:00
PrometheusRequestHandler.h Send only specific events/metrics for Keeper prometheus 2024-02-13 16:01:50 +01:00
ProtocolServerAdapter.cpp Rename 2023-09-01 12:55:58 +02:00
ProtocolServerAdapter.h Rename 2023-09-01 12:55:58 +02:00
ProxyV1Handler.cpp Better exception messages in input formats 2023-11-21 13:13:42 +00:00
ProxyV1Handler.h Updated implementation 2024-01-25 14:31:49 +03:00
ProxyV1HandlerFactory.h Updated implementation 2024-01-25 14:31:49 +03:00
ReplicasStatusHandler.cpp Fix db iterator wait during async metrics collection 2024-03-18 15:39:21 +00:00
ReplicasStatusHandler.h Revert "Revert "Use CH Buffer for HTTP out stream, add metrics for interfaces"" 2024-01-03 11:47:15 -05:00
ServerType.cpp Random changes in random files (#57642) 2023-12-14 12:47:11 +01:00
ServerType.h Random changes in random files (#57642) 2023-12-14 12:47:11 +01:00
StaticRequestHandler.cpp Rollback unnecessary style fixes 2024-06-13 11:21:48 +03:00
StaticRequestHandler.h Fix Static handler 2024-06-13 11:21:47 +03:00
TCPHandler.cpp Try fix data race in TCPHandler 2024-06-26 19:49:14 +02:00
TCPHandler.h Merge pull request #65744 from ClickHouse/try-fix-race-in-tcp-handler 2024-06-27 10:27:24 +00:00
TCPHandlerFactory.h Call getFQDNOrHostName() once 2024-02-02 14:33:34 +00:00
TCPProtocolStackData.h
TCPProtocolStackFactory.h Updated implementation 2024-01-25 14:31:49 +03:00
TCPProtocolStackHandler.h
TCPServer.cpp
TCPServer.h
TCPServerConnectionFactory.h
TLSHandler.cpp Fix CertificateReloader usage for custom protocols 2024-05-23 17:53:23 +02:00
TLSHandler.h Fix style 2024-05-22 14:10:50 +02:00
TLSHandlerFactory.h More parameters for tls layer in protocols 2024-05-16 18:34:17 +02:00
waitServersToFinish.cpp Convert unnecessary std::scoped_lock to std::lock_guard 2023-10-25 09:26:16 +00:00
waitServersToFinish.h Add missed #include <mutex> 2024-02-23 17:23:11 +03:00
WebUIRequestHandler.cpp Allow to map UI handlers to different paths 2024-02-25 23:04:39 +01:00
WebUIRequestHandler.h Fixing more headers 2024-02-29 15:40:30 +00:00