Fix a crash with BlockingCollection in Connection
The BlockingCollection would have `IsAddingCompleted` to true, but `IsComplete` to false, slipping through the cracks and causing an InvalidOperationException ("The collection has been marked as complete with regards to additions.") when trying to add to it.
We now add a check on `(Try)SendData` to only try to add if we can. The collection is still viable for reading until empty/`IsComplete`.
This commit is contained in:
@@ -434,7 +434,7 @@ namespace OpenRA.Server
|
||||
var ms = new MemoryStream(8);
|
||||
ms.WriteArray(BitConverter.GetBytes(ProtocolVersion.Handshake));
|
||||
ms.WriteArray(BitConverter.GetBytes(newConn.PlayerIndex));
|
||||
newConn.SendData(ms.ToArray());
|
||||
newConn.TrySendData(ms.ToArray());
|
||||
|
||||
// Dispatch a handshake order
|
||||
var request = new HandshakeRequest
|
||||
@@ -737,14 +737,10 @@ namespace OpenRA.Server
|
||||
|
||||
void DispatchFrameToClient(Connection c, int client, byte[] frameData)
|
||||
{
|
||||
try
|
||||
{
|
||||
c.SendData(frameData);
|
||||
}
|
||||
catch (Exception e)
|
||||
if (!c.TrySendData(frameData))
|
||||
{
|
||||
DropClient(c);
|
||||
Log.Write("server", $"Dropping client {client.ToString(CultureInfo.InvariantCulture)} because dispatching orders failed: {e}");
|
||||
Log.Write("server", $"Dropping client {client.ToString(CultureInfo.InvariantCulture)} because dispatching orders failed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user