Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConcurrentModificationException with quantum bridges on servers #4336

Closed
vincent-163 opened this issue Apr 12, 2020 · 6 comments
Closed

ConcurrentModificationException with quantum bridges on servers #4336

vincent-163 opened this issue Apr 12, 2020 · 6 comments

Comments

@vincent-163
Copy link

  • Minecraft Version: 1.12.2
  • AE2 Version: rv6-stable-7
  • Forge Version: 14.23.5.2847

Sorry for making a duplicate issue. I do realize that this bug has been reported many times, such as #3800 and duplicates such as #4149, #4210, #4287 and many others. However, since most of these issues are either closed or locked and the bug is affecting our server even with the latest version, we have to make a new issue in order to share some of our findings. Since most of the mods, as well as all other parts of Applied Energistics except for this particular bug are working fine, we're very interested in seeking a fix for this and would appreciate that for the benefit of both our server and the community as a whole.

We are using Forge server (no bukkit or sponge). The save works fine in a singleplayer client, but when used on a server it crashes seconds after the server is launched. The stack trace is omitted because it's similar to the other issues linked above.

We patched the mod following the build instructions and printed some stack traces around the place where ConcurrentModificationException occured. This one was particularly interesting: (line numbers in EnergyGridCache.java may be off a bit due to patched code)

image_2020-04-12_14-55-44

It seems like that while AE was drawing energy from the network, one of the energy devices was exhausted and caused its power state to become "Empty", which triggered block updates across the network. The Quantum Bridge then found that it was disconnected (maybe the other chunk was not loaded or not updated yet) and triggered a network recalculation and split into two different networks. The part with the updated Quantum Bridge is removed from the original network and moved into a new network. After all the event processing is done, the code tries to remove the energy device from the list of energy providers, but the iterator is already invalid because of the network recalculation.

By doing a fast git blame I found that NetworkEventBus have already accounted for the case where the AE network structure is changed while posting the event, and the code was introduced at d7e2ae8 as a fix for #3653. However, the callers of postEvent, such as what happened here, have yet to anticipate for such an edge case.

From my own coding experience, I would propose to postpone postEvent calls and put them in an event queue to be called later. That is to invoke subscribers async as opposed to sync and write an event loop to handle all events. However, I'm not sure if that would work out here, and insight from the developers is needed.

As a player, thank you for writing and maintaining such a powerful mod. As a developer, I understand how hard it is to fight bugs and respond to issues, and I'll not have you feel troubled for that.

@Apache553
Copy link

Apache553 commented Apr 12, 2020

I host the server. I will provide more details about that.

This crash happens in both singleplayer or multiplayer

To Reproduce
Step 1. Create a new game with only ae2 and ic2exp installed. Build a nether portal. Get a pair of Quantum Entangled Singularity.
ae1

Step 2. Go to the nether, build a Quantum Ring connected with a Energy Acceptor, put one of the singularity into the chamber. Place a IC2 Chunk Loader to keep these chunks loaded. Connect the IC2 Creative Generator to the Energy Acceptor.
ae2

  1. Go back to overworld. Build another Quantum Ring, put the singularity into it. Then connect the ring to ME Controller. Use IC2 Creative Generator to supply power.
    ae3

  2. Once the ME Controller connected to the generator the game crashes.

Expected behavior
Game shouldn't crash. The Quantum Ring should connect those two networks.

Additional context
Crash Report
latest.log
Screen Record : Streamable : you may want to turn down the volume since i forget to stop my music player XD

Environment

  • Minecraft Version: 1.12.2
  • AE2 Version: appliedenergistics2-rv6-stable-7
  • Forge Version: 14.23.5.2847

Personal thought
In my opinion, in function extractProviderPower in the class EnergyGridCache, the call to extractAEPower caused some function to modify the providers member. Iterator should become invalid if the underlying container has been modified and this modification isn't be done by this iterator. So after the extractAEPower call, the iterator in extractProviderPower might be invalid. If we do anything with this iterator, the exception should be thrown

@yueh
Copy link
Member

yueh commented Apr 12, 2020

Duplicate of #3800

@yueh yueh marked this as a duplicate of #3800 Apr 12, 2020
@Apache553
Copy link

yes i know it's duplicated but #3800 is no longer able to comment anything

@yueh
Copy link
Member

yueh commented Apr 12, 2020

The basic reason is clear, however there is no simple fix for it. (yet?)

Postponing is simply no an option as it would not shutdown a network once it losses power. Leading to various other issues.

The only real option I am currently seeing is refactoring the energy grid into a more explicit approach for cleaning up. E.g. introducing something like an invalid state instead of immediately dropping empty ones. But this would require an API break, which I will no longer do this late into the 1.12 development.

Or alternatively something about postponing grid rebuilds into the next tick, so it would no longer destroy the network immediately. Just power it down and maybe even have a chance of being charged next tick avoiding the whole rebuild. Which would also require a major change.

So as long as I do not see any quick way to fix it without introducing a bunch of new issues or forcing modpacks to abandon inactive AE2 addons due to an API break, it will most likely not be fixed.

@yueh yueh closed this as completed Apr 12, 2020
@vincent-163
Copy link
Author

vincent-163 commented Apr 12, 2020

Thanks for the explanation. However, I personally find keeping an unresolved issue closed causes confusion even if it can't be fixed, since this scatters discussion and forces people into making new issues whenever they encounter it. Could you please leave #3800 open so that discussion can take place in a central place?

Instead of closing the issue, you may give a tag like "help wanted" or "challenging", and in order to avoid overheated discussions you may edit the first comment to notify people of the rules.

@Apache553
Copy link

I made a workaround to this exception. Now the game will not crash in that case. The commit is here. It might be an alternative to refactoring in current stage.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants