Skip to content

Conversation

@UnlimitedBytes
Copy link
Contributor

Summary

Fixes a recursive deadlock in CraftWorld.isChunkGenerated that occurs when plugins (like Chunky) call the method from multiple threads simultaneously during chunk pre-generation.

Problem

The original implementation used managedBlock to process tasks while waiting for chunk data. When managedBlock processed tasks, it could execute other isChunkGenerated calls, which would also call managedBlock, creating:

  1. Unbounded recursion leading to stack overflow
  2. Deadlocks when threads wait on each other in circular patterns

Solution

  • Added a ThreadLocal<Boolean> flag to track when we're already inside isChunkGenerated
  • For cross-region calls: use future.join() without managedBlock to avoid recursive task processing
  • For on-region calls when chunk isn't in memory:
    • If recursive (flag is set): return false (conservative answer) without blocking
    • If first call (flag not set): use managedBlock normally to process chunk load

Behavior Change

Recursive calls to isChunkGenerated now return false when the chunk isn't immediately available in memory, rather than blocking. This is a conservative answer that:

  • Prevents deadlocks
  • Allows callers to retry if needed
  • For chunk pre-generation plugins, may cause some chunks to be rechecked but won't crash

Testing

  • All existing tests pass
  • Tested with Chunky chunk pre-generation plugin - no longer causes server hangs
  • Analyzed all isChunkGenerated usages in codebase - no breaking changes identified

@PureGero
Copy link
Contributor

What Chunky commands did you run to produce this?

@UnlimitedBytes
Copy link
Contributor Author

The commands used:

/chunky center
/chunky shape square
/chunky radius 1000
/chunky start
/stop
/chunky center
/chunky shape square
/chunky radius 5000
/chunky start
/chunky continue
/chunky confirm

This test was specifically designed to trigger this exception, it will not occur on normal use of the plugin, however it still will happen if multiple plugins try to check chunk generation at the same time.

@PureGero
Copy link
Contributor

I tried running those commands three times, no luck. Can you send the logs you got?

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