Fix possible terminate called for uncaught exception in Connection

This commit is contained in:
Kruglov Pavel 2023-04-24 16:57:43 +02:00 committed by GitHub
parent c2f240b8ee
commit 029c92344b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,12 +232,27 @@ 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.
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);
} }