Troubleshooting a desync
Posted: Mon Mar 04, 2019 11:36 pm
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?
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!
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?
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!