Fix ping instability caused by ghost sessions remaining in CastServer…#143
Merged
SoWeBegin merged 2 commits intoSoWeBegin:toybattles_mvsurgefrom Mar 23, 2026
Merged
Conversation
… 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>
SoWeBegin
requested changes
Mar 23, 2026
Owner
SoWeBegin
left a comment
There was a problem hiding this comment.
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>
Contributor
Author
|
Done. thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
… 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: