Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApiListener: Simplify deferred SSL shutdown in `NewClientHandlerInter… #10301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions lib/remote/apilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,18 +707,14 @@ void ApiListener::NewClientHandlerInternal(
return;
}

bool willBeShutDown = false;

Defer shutDownIfNeeded ([&sslConn, &willBeShutDown, &yc]() {
if (!willBeShutDown) {
// 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;

// 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]);
}
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;

// 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());
Expand Down Expand Up @@ -831,7 +827,7 @@ void ApiListener::NewClientHandlerInternal(
}
} catch (const boost::system::system_error& systemError) {
if (systemError.code() == boost::asio::error::operation_aborted) {
shutDownIfNeeded.Cancel();
shutdownSslConn.Cancel();
}

throw;
Expand Down Expand Up @@ -867,17 +863,15 @@ void ApiListener::NewClientHandlerInternal(

if (aclient) {
aclient->Start();

willBeShutDown = true;
shutdownSslConn.Cancel();
}
} else {
Log(LogNotice, "ApiListener", "New HTTP client");

HttpServerConnection::Ptr aclient = new HttpServerConnection(identity, verify_ok, client);
AddHttpClient(aclient);
aclient->Start();

willBeShutDown = true;
shutdownSslConn.Cancel();
}
}

Expand Down
Loading