Skip to content

Commit

Permalink
Merge pull request ClickHouse#65917 from azat/mysql-server-TLS-retries
Browse files Browse the repository at this point in the history
Fix possible issues with MySQL server protocol TLS connections
  • Loading branch information
alexey-milovidov authored Jul 2, 2024
2 parents 3b1e1d0 + 4f2a0e8 commit 9d8cc51
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Server/MySQLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ void MySQLHandler::run()

session->setClientConnectionId(connection_id);

const Settings & settings = server.context()->getSettingsRef();
socket().setReceiveTimeout(settings.receive_timeout);
socket().setSendTimeout(settings.send_timeout);

in = std::make_shared<ReadBufferFromPocoSocket>(socket(), read_event);
out = std::make_shared<WriteBufferFromPocoSocket>(socket(), write_event);
packet_endpoint = std::make_shared<MySQLProtocol::PacketEndpoint>(*in, *out, sequence_id);
Expand Down Expand Up @@ -451,6 +455,7 @@ void MySQLHandler::comQuery(ReadBuffer & payload, bool binary_protocol)

// Settings replacements
if (!should_replace)
{
for (auto const & [mysql_setting, clickhouse_setting] : settings_replacements)
{
const auto replacement_query_opt = setSettingReplacementQuery(query, mysql_setting, clickhouse_setting);
Expand All @@ -461,6 +466,7 @@ void MySQLHandler::comQuery(ReadBuffer & payload, bool binary_protocol)
break;
}
}
}

auto query_context = session->makeQueryContext();
query_context->setCurrentQueryId(fmt::format("mysql:{}:{}", connection_id, toString(UUIDHelpers::generateV4())));
Expand All @@ -470,6 +476,10 @@ void MySQLHandler::comQuery(ReadBuffer & payload, bool binary_protocol)
settings.prefer_column_name_to_alias = true;
query_context->setSettings(settings);

/// Update timeouts
socket().setReceiveTimeout(settings.receive_timeout);
socket().setSendTimeout(settings.send_timeout);

CurrentThread::QueryScope query_scope{query_context};

std::atomic<size_t> affected_rows {0};
Expand Down Expand Up @@ -643,7 +653,11 @@ void MySQLHandlerSSL::finishHandshakeSSL(
client_capabilities = ssl_request.capability_flags;
max_packet_size = ssl_request.max_packet_size ? ssl_request.max_packet_size : MAX_PACKET_LENGTH;
secure_connection = true;

ss = std::make_shared<SecureStreamSocket>(SecureStreamSocket::attach(socket(), SSLManager::instance().defaultServerContext()));
ss->setReceiveTimeout(socket().getReceiveTimeout());
ss->setSendTimeout(socket().getSendTimeout());

in = std::make_shared<ReadBufferFromPocoSocket>(*ss);
out = std::make_shared<WriteBufferFromPocoSocket>(*ss);
sequence_id = 2;
Expand Down

0 comments on commit 9d8cc51

Please sign in to comment.