Merge pull request #60769 from ClickHouse/catch-finalize-exception

Catch exceptions on finalize in `InterserverIOHTTPHandler`
This commit is contained in:
Antonio Andelic 2024-03-05 08:28:59 +01:00 committed by GitHub
commit 09924899ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -91,24 +91,35 @@ void InterserverIOHTTPHandler::handleRequest(HTTPServerRequest & request, HTTPSe
used_output.out = std::make_shared<WriteBufferFromHTTPServerResponse>(
response, request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD, keep_alive_timeout, write_event);
auto finalize_output = [&]
{
try
{
used_output.out->finalize();
}
catch (...)
{
tryLogCurrentException(log, "Failed to finalize response write buffer");
}
};
auto write_response = [&](const std::string & message)
{
auto & out = *used_output.out;
if (response.sent())
{
out.finalize();
finalize_output();
return;
}
try
{
writeString(message, out);
out.finalize();
writeString(message, *used_output.out);
finalize_output();
}
catch (...)
{
tryLogCurrentException(log);
out.finalize();
finalize_output();
}
};
@ -117,7 +128,7 @@ void InterserverIOHTTPHandler::handleRequest(HTTPServerRequest & request, HTTPSe
if (auto [message, success] = checkAuthentication(request); success)
{
processQuery(request, response, used_output);
used_output.out->finalize();
finalize_output();
LOG_DEBUG(log, "Done processing query");
}
else