diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index ca13e019..0e83c8b2 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -204,6 +204,12 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft *minecraft, LPVOID lpParame ProfileManager.SetDeferredSignoutEnabled(true); #endif + // Clear any stale cancel flag latched by the previous join's progress + // UI teardown, otherwise the next join's first tick insta-closes. + EnterCriticalSection(&bCancelRequestedCS); + g_NetworkManager.m_bCancelRequested = false; + LeaveCriticalSection(&bCancelRequestedCS); + int64_t seed = 0; bool dedicatedNoLocalHostPlayer = false; if (lpParameter != nullptr) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index 89b7cb6e..d06e4372 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -134,7 +134,14 @@ void CPlatformNetworkManagerStub::NotifyPlayerLeaving(IQNetPlayer* pQNetPlayer) if (socket != nullptr) { if (m_pIQNet->IsHost()) + { g_NetworkManager.CloseConnection(networkPlayer); + + // Propagate the TCP drop to the game Socket so any orphaned + // PendingConnection at this smallId cleans up before its login + // timer fires and leaks a DisconnectPacket to the reused slot. + socket->close(true); + } } if (m_pIQNet->IsHost()) diff --git a/Minecraft.World/Socket.cpp b/Minecraft.World/Socket.cpp index f07e3b2b..74e14889 100644 --- a/Minecraft.World/Socket.cpp +++ b/Minecraft.World/Socket.cpp @@ -493,6 +493,10 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, unsigned int } else { + // Don't write on a closing socket: an orphan whose smallId has been + // recycled would otherwise leak a packet onto the new client. + if( m_socket->isClosing() ) return; + XRNM_SEND_BUFFER buffer; buffer.pbyData = &b[offset]; buffer.dwDataSize = length;