-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a crash with BlockingCollection in Connection #20057
Conversation
Seems If you add this check here you may also need to add in Doesn't seem like a clean fix. The loop needs to take into account when Dispose was called. |
Also in the new netcode, data is copied so often byte by byte. Consider replacing
Dispose should wait for the loop to first have exited before setting CompleteAdded and returning. |
I'm not sure I follow. That said, there is probably little-to-no point in continuing to read from it and send out packets if things are being already disposed (or maybe we'd better send out what he have in the queue - I'm not sure and that's probably pretty situational). There are only two places where we add to the collection - the one I fixed and the public void SendData(byte[] data)
{
+ if (sendQueue.IsAddingCompleted)
+ return;
+
sendQueue.Add(data);
} but if we go down that path that may want to change to |
Imo it would be good to not throw these exceptions at all. |
ac18d04
to
2660af5
Compare
OK, went the |
Considering #20198 was merged which was the primary way (to my knowledge the only way) of triggering this bug I'm removing this from |
We need to reevaluate if this is still relevant. |
I randomly got this crash, here's what I did:
|
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`.
2660af5
to
6a2837f
Compare
I verified that that does make it crash rather reliably (on bleed). Not on the first kick, but if you try kicking several times it eventually crashes. |
The BlockingCollection would have
IsAddingCompleted
to true, butIsComplete
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.TO TEST:
![image](https://user-images.githubusercontent.com/7137365/171989739-d74cc30f-6a1f-43eb-8613-300c7b0f4324.png)
Launch the game, open Skirmish, open the map browser, click OK without selecting a map and then click Start Game.
In 95% of times you get this dialog:
(which I guess is a separate bug that should be addressed)
But sometimes the game will crash with the above.
I suggest also adding
with a breakpoint just below the changed
if
to catch when it would have crashed if you're feeling lucky.