ApiListener#ListenerCoroutineProc(): get remote endpoint ASAP for logging

On incoming connection timeout we log the remote endpoint which isn't
available if it was already disconnected - an exception is thrown.  Get it
as long as we're still connected not to lose it, nor to get an exception.
This commit is contained in:
Alexander A. Klimov 2024-02-09 12:27:25 +01:00
parent 01a6c4c1ce
commit 62e1d7650d
1 changed files with 5 additions and 4 deletions

View File

@ -513,6 +513,8 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Sha
server->async_accept(socket.lowest_layer(), yc);
auto remoteEndpoint (socket.lowest_layer().remote_endpoint());
if (!crlPath.IsEmpty()) {
time_t currentCreationTime = Utility::GetFileCreationTime(crlPath);
@ -531,12 +533,11 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Sha
auto strand (Shared<asio::io_context::strand>::Make(io));
IoEngine::SpawnCoroutine(*strand, [this, strand, sslConn](asio::yield_context yc) {
IoEngine::SpawnCoroutine(*strand, [this, strand, sslConn, remoteEndpoint](asio::yield_context yc) {
Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)),
[sslConn](asio::yield_context yc) {
[sslConn, remoteEndpoint](asio::yield_context yc) {
Log(LogWarning, "ApiListener")
<< "Timeout while processing incoming connection from "
<< sslConn->lowest_layer().remote_endpoint();
<< "Timeout while processing incoming connection from " << remoteEndpoint;
boost::system::error_code ec;
sslConn->lowest_layer().cancel(ec);