diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index 4453e440a..7640b83da 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -1120,21 +1120,22 @@ void Session::create_gen_auth_key_actor(HandshakeId handshake_id) { info.actor_ = create_actor( PSLICE() << get_name() << "::GenAuthKey", get_name(), std::move(info.handshake_), td::make_unique(DhCache::instance(), shared_auth_data_->public_rsa_key()), - PromiseCreator::lambda([self = actor_id(this)](Result> r_connection) { - if (r_connection.is_error()) { - if (r_connection.error().code() != 1) { - LOG(WARNING) << "Failed to open connection: " << r_connection.error(); - } - return; - } - send_closure(self, &Session::connection_add, r_connection.move_as_ok()); - }), PromiseCreator::lambda( - [self = actor_shared(this, handshake_id + 1), handshake_perf = PerfWarningTimer("handshake", 1000.1)]( - Result> handshake) mutable { - // later is just to avoid lost hangup - send_closure_later(std::move(self), &Session::on_handshake_ready, std::move(handshake)); + [self = actor_id(this), guard = callback_](Result> r_connection) { + if (r_connection.is_error()) { + if (r_connection.error().code() != 1) { + LOG(WARNING) << "Failed to open connection: " << r_connection.error(); + } + return; + } + send_closure(self, &Session::connection_add, r_connection.move_as_ok()); }), + PromiseCreator::lambda([self = actor_shared(this, handshake_id + 1), + handshake_perf = PerfWarningTimer("handshake", 1000.1), + guard = callback_](Result> handshake) mutable { + // later is just to avoid lost hangup + send_closure_later(std::move(self), &Session::on_handshake_ready, std::move(handshake)); + }), callback_); }