Skip to content

Commit

Permalink
Fix crash when previous connection with host ID already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchapyshev committed Aug 31, 2024
1 parent 65f1cba commit c647cce
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions source/router/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,27 +276,46 @@ bool Server::stopSession(Session::SessionId session_id)
//--------------------------------------------------------------------------------------------------
void Server::onHostSessionWithId(SessionHost* session)
{
if (!session)
{
LOG(LS_ERROR) << "Invalid session pointer";
return;
}

for (auto it = sessions_.begin(); it != sessions_.end();)
{
if (it->get()->sessionType() == proto::ROUTER_SESSION_HOST)
Session* other_session_ptr = it->get();

if (!other_session_ptr || other_session_ptr->sessionType() != proto::ROUTER_SESSION_HOST)
{
++it;
continue;
}

SessionHost* other_session = reinterpret_cast<SessionHost*>(other_session_ptr);
if (other_session == session)
{
++it;
continue;
}

bool is_found = false;

for (const auto& host_id : session->hostIdList())
{
SessionHost* other_session = reinterpret_cast<SessionHost*>(it->get());
if (other_session != session)
if (other_session->hasHostId(host_id))
{
for (const auto& host_id : session->hostIdList())
{
if (other_session->hasHostId(host_id))
{
LOG(LS_INFO) << "Detected previous connection with ID " << host_id;
LOG(LS_INFO) << "Detected previous connection with ID " << host_id;

it = sessions_.erase(it);
continue;
}
}
is_found = true;
break;
}
}

++it;
if (is_found)
it = sessions_.erase(it);
else
++it;
}
}

Expand Down

0 comments on commit c647cce

Please sign in to comment.