mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 10:02:01 +00:00
Merge pull request #49112 from ClickHouse/Avogar-patch-3
Fix possible terminate called for uncaught exception in some places
This commit is contained in:
commit
0beca0336d
@ -232,12 +232,28 @@ void Connection::disconnect()
|
|||||||
maybe_compressed_out = nullptr;
|
maybe_compressed_out = nullptr;
|
||||||
in = nullptr;
|
in = nullptr;
|
||||||
last_input_packet_type.reset();
|
last_input_packet_type.reset();
|
||||||
out = nullptr; // can write to socket
|
std::exception_ptr finalize_exception;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// finalize() can write to socket and throw an exception.
|
||||||
|
if (out)
|
||||||
|
out->finalize();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
/// Don't throw an exception here, it will leave Connection in invalid state.
|
||||||
|
finalize_exception = std::current_exception();
|
||||||
|
}
|
||||||
|
out = nullptr;
|
||||||
|
|
||||||
if (socket)
|
if (socket)
|
||||||
socket->close();
|
socket->close();
|
||||||
socket = nullptr;
|
socket = nullptr;
|
||||||
connected = false;
|
connected = false;
|
||||||
nonce.reset();
|
nonce.reset();
|
||||||
|
|
||||||
|
if (finalize_exception)
|
||||||
|
std::rethrow_exception(finalize_exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,7 +106,14 @@ WriteBufferFromPocoSocket::WriteBufferFromPocoSocket(Poco::Net::Socket & socket_
|
|||||||
|
|
||||||
WriteBufferFromPocoSocket::~WriteBufferFromPocoSocket()
|
WriteBufferFromPocoSocket::~WriteBufferFromPocoSocket()
|
||||||
{
|
{
|
||||||
finalize();
|
try
|
||||||
|
{
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,10 +93,13 @@ void InterserverIOHTTPHandler::handleRequest(HTTPServerRequest & request, HTTPSe
|
|||||||
|
|
||||||
auto write_response = [&](const std::string & message)
|
auto write_response = [&](const std::string & message)
|
||||||
{
|
{
|
||||||
if (response.sent())
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto & out = *used_output.out;
|
auto & out = *used_output.out;
|
||||||
|
if (response.sent())
|
||||||
|
{
|
||||||
|
out.finalize();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
writeString(message, out);
|
writeString(message, out);
|
||||||
@ -127,7 +130,10 @@ void InterserverIOHTTPHandler::handleRequest(HTTPServerRequest & request, HTTPSe
|
|||||||
catch (Exception & e)
|
catch (Exception & e)
|
||||||
{
|
{
|
||||||
if (e.code() == ErrorCodes::TOO_MANY_SIMULTANEOUS_QUERIES)
|
if (e.code() == ErrorCodes::TOO_MANY_SIMULTANEOUS_QUERIES)
|
||||||
|
{
|
||||||
|
used_output.out->finalize();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
|
||||||
|
@ -490,6 +490,7 @@ private:
|
|||||||
{
|
{
|
||||||
/// Stop ParallelFormattingOutputFormat correctly.
|
/// Stop ParallelFormattingOutputFormat correctly.
|
||||||
writer.reset();
|
writer.reset();
|
||||||
|
write_buf->finalize();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -955,6 +955,7 @@ private:
|
|||||||
{
|
{
|
||||||
/// Stop ParallelFormattingOutputFormat correctly.
|
/// Stop ParallelFormattingOutputFormat correctly.
|
||||||
writer.reset();
|
writer.reset();
|
||||||
|
write_buf->finalize();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -831,6 +831,7 @@ private:
|
|||||||
{
|
{
|
||||||
/// Stop ParallelFormattingOutputFormat correctly.
|
/// Stop ParallelFormattingOutputFormat correctly.
|
||||||
writer.reset();
|
writer.reset();
|
||||||
|
write_buf->finalize();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -480,6 +480,7 @@ void StorageURLSink::finalize()
|
|||||||
{
|
{
|
||||||
/// Stop ParallelFormattingOutputFormat correctly.
|
/// Stop ParallelFormattingOutputFormat correctly.
|
||||||
writer.reset();
|
writer.reset();
|
||||||
|
write_buf->finalize();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user