DarkRift
DarkRift copied to clipboard
TCP packets are received out of order
Quick Description
When sending packets using TCP, the order that they are received in is random due to how darkrift uses multiple threads internally.
Explanation
This issue was mentioned on the darkrift discord server a while ago, here is an example:
If you send two packets to the same client like so (on the same thread): client.SendMessage(message1, SendMode.Reliable); client.SendMessage(message2, SendMode.Reliable);
It is completely random whether the client receives it as: message1 message2 OR message2 message1
TCP itself guarantees that the data is received in the same order as it is sent, so this should definitely be made possible when using Darkrift too. Currently I would not be able to use darkrift in production due to this issue, so I hope it can be fixed at some point.
(Copied from Discord discussion)
It is by design, it's hard to do great performance and ordered messages. Even with a sequence number (which you actually don't need with TCP as you said earlier) if plugins are also multithreaded they could be handling two messages from a single client simultaneously
I did intend on adding ordered messages, I started a huge rework of the threading in DR so that messages could be processed in an order. Unordinal have the code if they want to continue it (or let me) and I was going to add ordered messages into that eventually
There was a small hack you could do as Ace mentions with the Bichannel listener but it forced all TCP messages to be completely synchronously processed per client
Putting this PR out there: https://github.com/DarkRiftNetworking/DarkRift/pull/156
I think that most people can live with plugins eating messages in an undefined order. It's when they are in full control of the code and it does not deliver messages in order which is very surprising behavior (e.g. impacting my own game).
I am not sure if DR2 itself should have sequence numbers above the listener layer - various HL framworks are being considered at the moment either way.
Should be solved in new version/master.