Skip to content

Fix ping instability caused by ghost sessions remaining in CastServer…#143

Merged
SoWeBegin merged 2 commits intoSoWeBegin:toybattles_mvsurgefrom
nadav78:fix/ping-ghost-sessions
Mar 23, 2026
Merged

Fix ping instability caused by ghost sessions remaining in CastServer…#143
SoWeBegin merged 2 commits intoSoWeBegin:toybattles_mvsurgefrom
nadav78:fix/ping-ghost-sessions

Conversation

@nadav78
Copy link
Copy Markdown
Contributor

@nadav78 nadav78 commented Mar 17, 2026

… rooms

When a player's TCP connection dropped mid-game, removeSession only erased them from the sessions map but left their weak_ptr in the room's m_playersVec. On reconnect (common after a wrong-password delay within the 10s heartbeat window), the new session joined alongside the ghost. Position broadcasts went to both. The ghost's still-open TCP socket caused ASIO completion handler backlog on the event loop, delaying pong (order 72) responses — high ping while alive, recovering while dead.

Fixes:

  • CastServer SessionsManager::removeSession now calls removePlayerFromRoom so players are evicted from rooms immediately on disconnect
  • Room::addPlayer lambda also removes expired weak_ptrs (was returning false for them, causing stale entries to accumulate forever)
  • Session::setSessionId releases the old pool ID before setting the new one, preventing CastServer session ID pool exhaustion after 500 connections
  • Session destructor no longer calls releaseSessionID explicitly; closeSocket already handles this (was a triple-release)
  • Removed static from PlayerPositionHandler response packet; std::move on a static left it in moved-from state on every subsequent call

… rooms

When a player's TCP connection dropped mid-game, removeSession only erased
them from the sessions map but left their weak_ptr in the room's m_playersVec.
On reconnect (common after a wrong-password delay within the 10s heartbeat
window), the new session joined alongside the ghost. Position broadcasts went
to both. The ghost's still-open TCP socket caused ASIO completion handler
backlog on the event loop, delaying pong (order 72) responses — high ping
while alive, recovering while dead.

Fixes:
- CastServer SessionsManager::removeSession now calls removePlayerFromRoom so
  players are evicted from rooms immediately on disconnect
- Room::addPlayer lambda also removes expired weak_ptrs (was returning false
  for them, causing stale entries to accumulate forever)
- Session::setSessionId releases the old pool ID before setting the new one,
  preventing CastServer session ID pool exhaustion after 500 connections
- Session destructor no longer calls releaseSessionID explicitly; closeSocket
  already handles this (was a triple-release)
- Removed static from PlayerPositionHandler response packet; std::move on a
  static left it in moved-from state on every subsequent call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@SoWeBegin SoWeBegin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good, but in PlayerPositionHandler the "static" was not wrong since we explicitly set the Option (which is the total packet's data). Please re-add that and I'll merge this one.

Thanks!

The static is intentional — setData is called explicitly on each invocation,
so the moved-from state is not an issue in practice.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nadav78
Copy link
Copy Markdown
Contributor Author

nadav78 commented Mar 23, 2026

Done. thanks!

@SoWeBegin SoWeBegin merged commit 5c69c81 into SoWeBegin:toybattles_mvsurge Mar 23, 2026
1 check passed
@nadav78 nadav78 deleted the fix/ping-ghost-sessions branch March 25, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants