Page 1 of 1

Troubleshooting a desync

Posted: Mon Mar 04, 2019 11:36 pm
by PantherX
Before I start, I realise this is going down the rabbit hole a bit because desyncs can be quite tricky to narrow down. I'm trying to be a good mod citizen and learn how to avoid these from happening but still have lots of problems I can't seem to solve. I understand Factorio is deterministic and why desyncs are a necessary evil, but I'm trying to get a better understanding of how to interpret the desync report to find what it is in my mod that causes the desync to happen. There's threads on the forum that cover various parts of this, but nothing that I was able to solve my current issues with. So here goes...

My first question is, what is the best place to start in the desync report? Is the reference level the state before the desync occurred?

I currently have a desync that I can reproduce in my local setup (with 2 copies of Factorio running side by side) and it happens every time a modded entity is built but it only happens in games where there are lots of other mods. For instance, if I run a local game with only my mod in it, it doesn't desync at all. When there's lots of other mods, it does but only the remote player is desynced. The server keeps running fine. I'm not sure if that's a clue either? In trying so solve this particular issue, I can see when I diff files like script.dat, that there are changes between the reference and desync level and I'm not sure if this is something I need to dig into? For instance, the diff below shows that a different entitytarget was stored in the global table between the 2 levels but I'm not sure if this is a problem or not?

Image

I wonder if this is part of the cause as this is the information that is written when the entity is placed. But there's also GUI things that happen around the same time and so I'm not sure which part of my code I should look further into. Are there some golden rules with regards to desyncs I should be taking heed of?

If anyone has any advice it would be much appreciated. I'm trying to avoid just uploading endless desyncs to the bug report forum and expecting someone to just magically work it out. I'm trying to learn how to actually resolve these and make this a better experience for everyone! :D

Re: Troubleshooting a desync

Posted: Tue Mar 05, 2019 12:25 am
by Bilka
I find the easiest way to just go through the code of the mod that's desyncing and looking for things like wrong on_load usage, mutable data that's stored outside of global for more than a tick etc. So I took a look at your mod. It's an adventure in unnecessary functions, but looks desync safe, so it's probably not your mod's fault.

Re: Troubleshooting a desync

Posted: Tue Mar 05, 2019 12:39 am
by PantherX
Thanks for taking a look. I agree with the observation about the functions... I'm slowly trying to clean it all up! If it's another mod causing it, is there an easy way to narrow down where that might be? The desync I was sent has 57 mods installed! :shock:

Re: Troubleshooting a desync

Posted: Wed Mar 06, 2019 1:47 am
by PantherX
Is it possible that there's a limit to the number of GUI elements that can be synced in a multiplayer game? I'm noticing that if I draw a GUI with a small number of child elements it's fine, but once it goes over about 1000 children, then desyncs occur. In single player, it doesn't seem to have a problem with any number of children. Am I hitting some sort of limit?

Re: Troubleshooting a desync

Posted: Thu Mar 07, 2019 2:44 am
by PantherX
Okay, posting an update here in case anyone searches for this in future... Bilka was right and it was being caused by another mod. It wasn't easy to troubleshoot (lots of testing one by one and restarting the game) but I was ultimately able to fix the issue by adding special handling whenever the other mod is present.

I'm still interested if anyone has any other useful tips for desync troubleshooting though. :)

Re: Troubleshooting a desync

Posted: Thu Mar 07, 2019 9:15 am
by Bilka
Muppet made a wiki page that might help a bit: https://wiki.factorio.com/Desynchronization

Re: Troubleshooting a desync

Posted: Thu Mar 07, 2019 10:31 pm
by PantherX
Bilka wrote:
Thu Mar 07, 2019 9:15 am
Muppet made a wiki page that might help a bit: https://wiki.factorio.com/Desynchronization
Thanks, that is very helpful indeed!