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

fix(AutoReloadAssetTypeManager): synchronize methods to avoid NPE #102

Merged
merged 2 commits into from
Apr 27, 2021

Conversation

keturn
Copy link
Member

@keturn keturn commented Apr 24, 2021

switchEnvironment leaves a closed reloadOnChangeHandler for a moment, which caused reloadChangedAssets() to crash if called from another thread.

I don't believe this is the most efficient locking strategy for this, but the ergonomics of marking methods as synchronized are so much better than using Lock.lock(). I tried a few other things but they added a ton of noise to the code, so I decided to submit this more readable version until we find something wrong with it.

I have very little experience managing thread safety in Java and am extra open to suggestions on this one.

Blocks MovingBlocks/Terasology#4622

Test plan

MTE tests run under MovingBlocks/Terasology#4622 consistently crash without a fix for this. Should be able to reproduce with something like

./gradlew :modules:Health:integrationTest

…inter Exception during switchEnvironment

switchEnvironment leaves a closed reloadOnChangeHandler for a moment, which caused reloadChangedAssets() to crash if called from another thread.
Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable to me. However, I likely have even less experience with thread safety in Java, so feel free to wait for a review from somebody else 😅

@keturn
Copy link
Member Author

keturn commented Apr 27, 2021

Sounds reasonable to me. However, I likely have even less experience with thread safety in Java, so feel free to wait for a review from somebody else 😅

It's a topic that's worth some attention, but I get the feeling I should not hold my breath for it.

I rate this as a low-risk change, so I'm going to go ahead and merge it.

If we find reloadChangedAssets causing things to stutter we can come back and give it another look.

@keturn keturn merged commit f459dac into release/v7.x Apr 27, 2021
@keturn keturn deleted the v7/fix/unsafeAssetTypeManager branch April 27, 2021 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants