From e68132832c411b1b825d62ecb780f0549ab94cf8 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Thu, 28 Dec 2017 20:55:51 -0700 Subject: [PATCH] Acquire connectionLock in CMClient::Disconnected to handle concurrent Disconnected race --- SteamKit2/SteamKit2/Steam/CMClient.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SteamKit2/SteamKit2/Steam/CMClient.cs b/SteamKit2/SteamKit2/Steam/CMClient.cs index 32674fbbd..a18b9f670 100644 --- a/SteamKit2/SteamKit2/Steam/CMClient.cs +++ b/SteamKit2/SteamKit2/Steam/CMClient.cs @@ -402,15 +402,19 @@ void Disconnected( object sender, DisconnectedEventArgs e ) SessionID = null; SteamID = null; + lock ( connectionLock ) + { + if ( connection == null ) return; - connection.NetMsgReceived -= NetMsgReceived; - connection.Connected -= Connected; - connection.Disconnected -= Disconnected; - connection = null; + connection.NetMsgReceived -= NetMsgReceived; + connection.Connected -= Connected; + connection.Disconnected -= Disconnected; + connection = null; - heartBeatFunc.Stop(); + heartBeatFunc.Stop(); - OnClientDisconnected( userInitiated: e.UserInitiated || ExpectDisconnection ); + OnClientDisconnected( userInitiated: e.UserInitiated || ExpectDisconnection ); + } } internal static IPacketMsg GetPacketMsg( byte[] data )