correctly handle shutdown when tls was not established yet

This commit is contained in:
Vito
2025-09-04 12:40:11 +02:00
parent 80c8a2e969
commit a5bdb3cef5
2 changed files with 12 additions and 9 deletions

View File

@@ -136,14 +136,16 @@ ConnectAttempt::tryAsyncShutdown()
return;
shutdownStarted_ = true;
// gracefully shutdown the SSL socket, performing a shutdown handshake
stream_.async_shutdown(bind_executor(
strand_,
std::bind(
&ConnectAttempt::onShutdown,
shared_from_this(),
std::placeholders::_1)));
if (handshakeComplete_)
return stream_.async_shutdown(bind_executor(
strand_,
std::bind(
&ConnectAttempt::onShutdown,
shared_from_this(),
std::placeholders::_1)));
close();
}
void
@@ -306,6 +308,8 @@ ConnectAttempt::onHandshake(error_code ec)
if (ec)
return fail("onHandshake", ec);
handshakeComplete_ = true;
// check if we connected to ourselves
if (!overlay_.peerFinder().onConnected(
slot_, beast::IPAddressConversion::from_asio(local_endpoint)))
@@ -349,8 +353,6 @@ ConnectAttempt::onHandshake(error_code ec)
void
ConnectAttempt::onWrite(error_code ec)
{
cancelTimer();
ioPending_ = false;
if (ec)

View File

@@ -65,6 +65,7 @@ private:
bool shutdown_ = false;
bool ioPending_ = false;
bool shutdownStarted_ = false;
bool handshakeComplete_ = false;
public:
ConnectAttempt(