From 62e1d7650d317b5e28989f526c88460ffc9dad0e Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 9 Feb 2024 12:27:25 +0100 Subject: [PATCH] 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. --- lib/remote/apilistener.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 85443e21850..08cb62cab16 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -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::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);