Skip to content

Commit 6d9be17

Browse files
committed
Revert "Fix: keep socket alive during async_connect to prevent use-after-free crash"
This reverts commit 2ec6b20.
1 parent 2ec6b20 commit 6d9be17

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

lib/ClientConnection.cc

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -642,19 +642,12 @@ void ClientConnection::handleResolve(ASIO_ERROR err, const tcp::resolver::result
642642
ptr->connectTimeoutTask_->stop();
643643
});
644644
connectTimeoutTask_->start();
645-
// Capture socket_ by value (shared_ptr) to ensure the socket object stays alive for
646-
// the entire duration of async_connect. ASIO's range_connect_op holds a raw reference
647-
// to the socket and calls socket.close() between endpoint retry attempts; if
648-
// ClientConnection is destroyed (dropping the socket_ shared_ptr) before those
649-
// internal calls complete, that results in a use-after-free crash.
650-
auto socket = socket_;
651-
ASIO::async_connect(*socket_, results,
652-
[weakSelf, socket](const ASIO_ERROR& err, const tcp::endpoint& endpoint) {
653-
auto self = weakSelf.lock();
654-
if (self) {
655-
self->handleTcpConnected(err, endpoint);
656-
}
657-
});
645+
ASIO::async_connect(*socket_, results, [weakSelf](const ASIO_ERROR& err, const tcp::endpoint& endpoint) {
646+
auto self = weakSelf.lock();
647+
if (self) {
648+
self->handleTcpConnected(err, endpoint);
649+
}
650+
});
658651
}
659652

660653
void ClientConnection::readNextCommand() {

0 commit comments

Comments
 (0)