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

ThreadLocalRandom accessed from a different thread (C2ME forge) #17

Closed
Dreaming-Codes opened this issue Oct 25, 2024 · 11 comments
Closed

Comments

@Dreaming-Codes
Copy link

Hi,

I'm experiencing a problem on my server where it eventually crashes. The issue seems to arise from a java.util.ConcurrentModificationException, specifically related to ThreadLocalRandom being accessed from a different thread than its owner. Here's a snippet of the error message:

java.util.ConcurrentModificationException: ThreadLocalRandom accessed from a different thread (owner: Server thread, current: ForkJoinPool.commonPool-worker-16)
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.handleNotOwner(CheckedThreadLocalRandom.java:55) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23966!/:?]
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.isSafe(CheckedThreadLocalRandom.java:38) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23966!/:?]
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.m_64707_(CheckedThreadLocalRandom.java:86) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23966!/:?]
	at net.minecraft.world.level.levelgen.BitRandomSource.m_188503_(BitRandomSource.java:33) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at net.minecraft.util.Mth.m_216287_(net/minecraft/util/Mth.java:734) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at com.yungnickyoung.minecraft.yungscavebiomes.block.entity.RareIceBlockEntity.tick(RareIceBlockEntity.java:23) ~[YungsCaveBiomes-1.20.1-Forge-2.0.1.jar%23432!/:1.20.1-Forge-2.0.1]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.mixinextras$bridge$m_155252_$11(LevelChunk.java) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.wrapOperation$bfd000$tt20$onTick(net/snackbag/tt20/mixin/world/WorldChunkMixin.java [tt20.mixins.json]:24) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.m_142224_(net/minecraft/world/level/chunk/LevelChunk$BoundTickingBlockEntity.java:689) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$RebindableTickingBlockEntityWrapper.m_142224_(LevelChunk.java:782) ~[server-1.20.1-20230612.114412-srg.jar%23435!/:?]
	at me.thegiggitybyte.sleepwarp.runnable.BlockTickRunnable.run(BlockTickRunnable.java:17) ~[sleepwarp-2.2.0_rc1+1.20.1_mapped_srg_1.20.1.jar%23988!/:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387) ~[?:?]
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312) ~[?:?]
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843) ~[?:?]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808) ~[?:?]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188) ~[?:?]
[25Oct2024 17:47:53.737] [ForkJoinPool.commonPool-worker-17/ERROR] [CheckedThreadLocalRandom/]: ThreadLocalRandom accessed from a different thread (owner: Server thread, current: ForkJoinPool.commonPool-worker-17)
This is usually NOT a bug in C2ME, but a bug in another mod or in vanilla code. 
Possible solutions: 
  - Find possible causes in the stack trace below and 
    - if caused by another mod, report this to the corresponding mod authors 
    - if no other mods are involved, report this to C2ME 

This error message is repeatedly logged, leading to the server becoming unresponsive and crashing after about a minute. Occasionally, the issue resolves itself without a crash, but this is rare.

I'm using the C2ME port from this repository: C2ME-fabric 1.20.1 with Synatra connector.

For more details, you can view the full log here: Log File.

@Dreaming-Codes
Copy link
Author

#16 might be related

@Dreaming-Codes
Copy link
Author

I'm also using https://github.com/AnOpenSauceDev/FastRandom which uses ThreadLocalRandom under the hood so it may be related

@yungnickyoung
Copy link
Member

Huh, that's weird. Accessing the level random should be safe from a block entity. In fact, vanilla does this exact same thing in SculkShriekerBlockEntity#playWardenReplySound, so I'm assuming my usage is also not a problem

@Dreaming-Codes
Copy link
Author

Huh, that's weird. Accessing the level random should be safe from a block entity. In fact, vanilla does this exact same thing in SculkShriekerBlockEntity#playWardenReplySound, so I'm assuming my usage is also not a problem

Just removed FastRandom I'll let you know if I notice any difference

@Dreaming-Codes
Copy link
Author

@yungnickyoung Just encountered the same issue even without FastRandom https://mclo.gs/vCTs4Wb

java.util.ConcurrentModificationException: ThreadLocalRandom accessed from a different thread (owner: Server thread, current: ForkJoinPool.commonPool-worker-37)
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.handleNotOwner(CheckedThreadLocalRandom.java:55) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23961!/:?]
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.isSafe(CheckedThreadLocalRandom.java:38) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23961!/:?]
	at com.ishland.c2me.fixes.worldgen.threading_issues.common.CheckedThreadLocalRandom.m_64707_(CheckedThreadLocalRandom.java:86) ~[c3me-fabric-mc1.20.1-0.2.0-c3me-alpha.11.69$c2me-fixes-worldgen-threading-issues-mc1.20.1-0.2.0-c3me-alpha.11.69_mapped_srg_1.20.1.jar%23961!/:?]
	at net.minecraft.world.level.levelgen.BitRandomSource.m_188503_(BitRandomSource.java:33) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at net.minecraft.util.Mth.m_216287_(net/minecraft/util/Mth.java:734) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at com.yungnickyoung.minecraft.yungscavebiomes.block.entity.RareIceBlockEntity.tick(RareIceBlockEntity.java:23) ~[YungsCaveBiomes-1.20.1-Forge-2.0.1.jar%23430!/:1.20.1-Forge-2.0.1]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.mixinextras$bridge$m_155252_$11(LevelChunk.java) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.wrapOperation$bfd000$tt20$onTick(net/snackbag/tt20/mixin/world/WorldChunkMixin.java [tt20.mixins.json]:24) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity.m_142224_(net/minecraft/world/level/chunk/LevelChunk$BoundTickingBlockEntity.java:689) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at net.minecraft.world.level.chunk.LevelChunk$RebindableTickingBlockEntityWrapper.m_142224_(LevelChunk.java:782) ~[server-1.20.1-20230612.114412-srg.jar%23433!/:?]
	at me.thegiggitybyte.sleepwarp.runnable.BlockTickRunnable.run(BlockTickRunnable.java:17) ~[sleepwarp-2.2.0_rc1+1.20.1_mapped_srg_1.20.1.jar%23982!/:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387) ~[?:?]
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312) ~[?:?]
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843) ~[?:?]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808) ~[?:?]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188) ~[?:?]
[26Oct2024 11:07:48.790] [Server thread/INFO] [de.mrjulsen.crn.CreateRailwaysNavigator/]: All times have been corrected: 3 Ticks
[26Oct2024 11:07:48.947] [Server thread/INFO] [de.mrjulsen.crn.CreateRailwaysNavigator/]: All times have been corrected: 3 Ticks
[26Oct2024 11:07:49.069] [Server thread/INFO] [de.mrjulsen.crn.CreateRailwaysNavigator/]: All times have been corrected: 2 Ticks
[26Oct2024 11:07:49.076] [ForkJoinPool.commonPool-worker-38/ERROR] [CheckedThreadLocalRandom/]: ThreadLocalRandom accessed from a different thread (owner: Server thread, current: ForkJoinPool.commonPool-worker-38)
This is usually NOT a bug in C2ME, but a bug in another mod or in vanilla code. 
Possible solutions: 
  - Find possible causes in the stack trace below and 
    - if caused by another mod, report this to the corresponding mod authors 
    - if no other mods are involved, report this to C2ME 

@Dreaming-Codes
Copy link
Author

Dreaming-Codes commented Oct 26, 2024

I've developed a mod that mixin into yours to disable that method. If anyone else is experiencing this issue and need an immediate solution, you can download the mod here: GitHub - Dreaming-Codes/fix-yungs-cave-biomes/releases.

@Dreaming-Codes
Copy link
Author

Okay nvm, it seams that the problem was due to the sleepwarp mod running via connector, I'll keep this issue open for a day or two more just to be sure it's solved

@CaoTrongThang
Copy link

Okay nvm, it seams that the problem was due to the sleepwarp mod running via connector, I'll keep this issue open for a day or two more just to be sure it's solved

i might don't understand but i need to download the fix-yungs-cave-biomes mod to fix my current bug right?

1 similar comment
@CaoTrongThang
Copy link

Okay nvm, it seams that the problem was due to the sleepwarp mod running via connector, I'll keep this issue open for a day or two more just to be sure it's solved

i might don't understand but i need to download the fix-yungs-cave-biomes mod to fix my current bug right?

@yungnickyoung
Copy link
Member

yungnickyoung commented Nov 26, 2024

Okay nvm, it seams that the problem was due to the sleepwarp mod running via connector, I'll keep this issue open for a day or two more just to be sure it's solved

@Dreaming-Codes Just to verify, was this resolved?

@Dreaming-Codes
Copy link
Author

Dreaming-Codes commented Nov 26, 2024

Okay nvm, it seams that the problem was due to the sleepwarp mod running via connector, I'll keep this issue open for a day or two more just to be sure it's solved

@Dreaming-Codes Just to verify, was this resolved?

Yes sorry I forgot, I can confirm it was due to the sleepwarp mod running with Synatra connector

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

No branches or pull requests

3 participants