Merge pull request #10301 from Icinga/ssl-shutdown-new-client-handler

ApiListener: Simplify deferred SSL shutdown in `NewClientHandlerInter…
This commit is contained in:
Yonas Habteab 2025-03-17 13:12:03 +01:00 committed by GitHub
commit 3083a32bc6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -707,18 +707,14 @@ void ApiListener::NewClientHandlerInternal(
return; return;
} }
bool willBeShutDown = false; Defer shutdownSslConn ([&sslConn, &yc]() {
// Ignore the error, but do not throw an exception being swallowed at all cost.
// https://github.com/Icinga/icinga2/issues/7351
boost::system::error_code ec;
Defer shutDownIfNeeded ([&sslConn, &willBeShutDown, &yc]() { // Using async_shutdown() instead of AsioTlsStream::GracefulDisconnect() as this whole function
if (!willBeShutDown) { // is already guarded by a timeout based on the connect timeout.
// Ignore the error, but do not throw an exception being swallowed at all cost. sslConn.async_shutdown(yc[ec]);
// https://github.com/Icinga/icinga2/issues/7351
boost::system::error_code ec;
// Using async_shutdown() instead of AsioTlsStream::GracefulDisconnect() as this whole function
// is already guarded by a timeout based on the connect timeout.
sslConn.async_shutdown(yc[ec]);
}
}); });
std::shared_ptr<X509> cert (sslConn.GetPeerCertificate()); std::shared_ptr<X509> cert (sslConn.GetPeerCertificate());
@ -831,7 +827,7 @@ void ApiListener::NewClientHandlerInternal(
} }
} catch (const boost::system::system_error& systemError) { } catch (const boost::system::system_error& systemError) {
if (systemError.code() == boost::asio::error::operation_aborted) { if (systemError.code() == boost::asio::error::operation_aborted) {
shutDownIfNeeded.Cancel(); shutdownSslConn.Cancel();
} }
throw; throw;
@ -867,8 +863,7 @@ void ApiListener::NewClientHandlerInternal(
if (aclient) { if (aclient) {
aclient->Start(); aclient->Start();
shutdownSslConn.Cancel();
willBeShutDown = true;
} }
} else { } else {
Log(LogNotice, "ApiListener", "New HTTP client"); Log(LogNotice, "ApiListener", "New HTTP client");
@ -876,8 +871,7 @@ void ApiListener::NewClientHandlerInternal(
HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client); HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client);
AddHttpClient(aclient); AddHttpClient(aclient);
aclient->Start(); aclient->Start();
shutdownSslConn.Cancel();
willBeShutDown = true;
} }
} }