Wrap thread factory set context class loader in a try #1771
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Issue
I was experiencing a rare crash upon starting a Create contraption and opening a Tom's Storage terminal blaming Sinytras Thread Factory "setContextClassLoader" line. I was unable to reproduce it with a minimal set of mods, nor was i able to reproduce it consistently in a reasonable time frame (took 10+ hours to reproduce once)
Tom's Storage: https://pastebin.com/xW0sDscN
Create: https://pastebin.com/E2bYNWKJ
While the crash with the Tom's Storage Terminal was savable (a simple re-log fixed it) the Create crash would delete all active contraptions in my world.
Neruina was capable of catching the Tom's Storage Terminal crash and recover with no side effects, but it was unable to catch the Create crash at all.
The Proposal
Wrap thread factory set context class loader in a try
Possible Side Effects
if anything ever tries to check what the class loader context is on a thread after the try failed, possible crash/error? I've not had any issues with 200+ hours playing on a very large modpack after making this change though.
Alternatives
I'll be honest, im not familiar with managing threads at all, im still a fairly novice modder. I'm not sure what the alternative would be, especially without knowing exactly why its happening in the first place.
Additional Notes
Apologies I know I wasnt able to properly reproduce the issue, which is why I have not made an issue about it, however I thought I'd atleast report my findings as I believe I've found a solution. After making this change, I have not been able to intentionally recreate the crash with Tom's Storage or Create, and have been playing normally on my world for 200+ hours since with no related issues. I have seen the log output I added to the catch a handful of times, and not seen any abnormalities in gameplay other than a very brief lag spike surrounding it.
I left the log output on catch in, just in case it ever pops up in issues in the future it will be easier to be related to this, and with how rare this case is, this wont result in log spam.