Forums > Diary > Network error
Jattenalle
Developer
Joined 4438 days ago
Last seen 5 days ago
Network error
Posted 1464 days ago
Update
This bug should be fixed as of 2.20.800!

Original post
We are aware of an error when trying to sign in.
Tracking down the root cause led us to find some nasty problems.

With the help of players Auios, and Boxpipe, and administrator Uncle_PaiPai, I have managed to narrow the problem down.

But it is midnight here, and I need some sleep. Will update in the morning!
Awake and working!

The bug
The server and clients communicate via small chunks of data, for our example: xxxxxxxx
When data is sent, it's bundled together, and a header is added to each chunk, so if there were two chunks waiting to be sent by the server it would look like: AAxxxxxxxxBBxxxxxxxx
Where AA and BB are chunk types that indicate what kind, and how much, data should be read.

The problem is that on the client the network packet might arrive as:
AAxxxx
(Note, not enough x's!)
The client reads that it is a type AA chunk, tries to read 8 x's, can't. Discards it.
But then the next network packet arrives, and looks like:
xxxxBBxxxxxxxx
The client now reads those first two xx's as the chunk type, which usually means it detects an unknown chunk type and discards the remaining data completely.
The remaining data is discarded because we don't know how much ''garbage'' (leading x's) to discard to get to the next real chunk type indicator.

This bug has been present for a long time, debug logs that contain the lines
UNKNOWN PACKET TYPE: xx
Remaining buffer of ? bytes have been purged!
... have been submitted pretty much since forever. But they were always in relation to other bugs, and the signs were overlooked.

The cause of the bug is down to how networking works, data is sent in network packets that can be split in multiple ways and take different paths to arrive at the client. Once they arrive at the client they are automatically re-assembled in the correct order to be read.
What happens is that the client sees there is data to read, but not all data has arrived yet, causing it to read the partial network packets as shown above.

It wasn't caught on my end for two of reasons:
  • I have fast, congestion-less internet
  • The server is very close to me
Which meant that, for me, by the time the client started reading network data, either all of it had already arrived, or would be arriving before the client ever hit a problem.
This also explains why some people never showed the symptoms: good/fast internet.

The solution is to add a small header to every network packet that shows how much data is expected. This way the client will wait to process the network data until all of the expected data has arrived.

The code is fairly simple and straightforward, working on it now!
Forums > Diary > Network error
Steam Early-access
Gods and Idols
Gods and Idols is copyright © Johannes Pihl 2007-2019, all rights reserved;
Shadowbox.js is © Michael J. I. Jackson;
All other trademarks, logos and copyrights are the property of their respective owners.