diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index 10736607..7c3e8c64 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -232,19 +232,19 @@ private void ExecutePeerShutdown() foreach (var conn in m_connections) if (conn != null) list.Add(conn); + } - lock (m_handshakes) - { - foreach (var hs in m_handshakes.Values) - if (hs != null) - list.Add(hs); - - // shut down connections - foreach (NetConnection conn in list) - conn.Shutdown(m_shutdownReason); - } + lock (m_handshakes) + { + foreach (var hs in m_handshakes.Values) + if (hs != null && list.Contains(hs) == false) + list.Add(hs); } + // shut down connections + foreach (NetConnection conn in list) + conn.Shutdown(m_shutdownReason); + FlushDelayedPackets(); // one final heartbeat, will send stuff and do disconnect