Near-infinite loop in EnergyNetwork
kryptx opened this issue ยท 3 comments
Unfortunately this is the worst kind of bug -- does not reproduce 100% of the time and does not result in a crash. I think I've made as much progress as I can make on my own (Java's not my forte), though I'm willing to continue to investigate and/or submit a fix, assuming I haven't made it obvious to you what the issue is. I might need some assistance, particularly in getting better line numbers for my debugger and building a jar from source that will load properly on my server.
The issue from a user's perspective is that in SMP, a few seconds after starting to use a machine, all players' connections to the server may be lost, as if the server had lost its internet connection. If that happens, they will be unable to reconnect either for a very long time -- I didn't actually wait long enough -- or until an admin restarts the server. Even then, it's possible that reconnecting and loading the offending chunk(s) will immediately cause the same symptom. If the server is restarted enough times, eventually this will relieve itself and everything works normally. This happened for me using version 7.0.0.84.
Reproduction
(or, my best attempt at it)
Here's an image of the setup that I was using. I have other machines connected, but based on my debugging this (and, I think, having BuildCraft installed) should be all that's needed to potentially reproduce the issue. Black lines are pressurized tubes, blue lines are universal cables (mostly elite, but a few advanced branching out to the solar generators).
Also it seems that it only occurs if starting when the system is 'at rest'; that is, the cube and all machines are full of energy, and both the factory and electrolytic separator are full of oxygen. Then just put some ore into the factory (I have 3 speed upgrades and 3 energy upgrades as well). It should seize up before it has finished processing the first ore. For me, I'd say it happens about 30% of the time.
Note that there is an Aqueous Accumulator from TE4. I doubt that it's relevant, but for posterity, here's a complete list of mods that I have installed on this server.
Debugging effort
top
showed 100% CPU usage (multicore machine, so this was just a single thread at 100%). Using a debugger, I found that the energy cube needed a fair amount of energy -- several thousand -- but returned an extremely small number for maxReceivedPerCycle()
, somewhere between 0.0001 and 0.000001. Since receptor.doWork()
is only called if a certain amount of in-game time has passed, this value was never allowed to update and the do-while loop in EnergyNetwork.tickEmit()
would almost infinitely set tryAgain
to true. If I called receptor.doWork()
manually with the debugger, the system returned to normal.
More info
Seems possibly relevant that this line is reached when no BuildCraft machines are connected. When this occurs, sent
is not being modified in any other place in this method, in any iteration of the loop. Maybe that is part of the issue (i.e. EnergyCube is being treated as a BuildCraft power receptor?); I'm not familiar enough with your codebase yet to understand how this is all intended to work. Hopefully this screencap will be somewhat helpful. Note the values of energyToSend
and toSend
.
It seems this is using an outdated build - attempt updating to the very latest version of Mekanism and tell me if you have the same issue. The code I see includes a change that was reverted a while ago that fixed incompatibilities with mods that incorrectly implemented multiple energy APIs - it may have been the issue.
After going over the code again, I can confirm that this is the issue - I will be pushing v7.1 in the next few days that will contain the fix :)