Skip to content

Bedrock entity spawn crashes during chunk generation on Gen-Pool threads (no Tokio runtime) #2291

Description

@as7ar

I've searched existing issues and couldn't find a duplicate.

  • I confirm this is not a duplicate.

Operating System

Windows 11 Pro

Server Software Version/Commit

0.1.0-dev+26.1 (Commit: 461a5eb/release)

What happened?

When a Bedrock client is connected, Pumpkin crashes during chunk generation with:

full log
https://pastes.dev/m5ulw0F11V
there is no reactor running, must be called from the context of a Tokio 1.x runtime
Panic Location: pumpkin/src/net/bedrock/mod.rs:1213:29
Thread: Gen-Pool-5

The panic occurs at:

Some(self.tasks.spawn(task))

Tracing the call path:

world.broadcast_entity_spawn()
    ↓
player.client.try_enqueue_spawn_packet(entity)
    ↓
BedrockClient::enqueue_spawn_packet()
    ↓
BedrockClient::spawn_task()
    ↓
self.tasks.spawn(task)
    ↓
panic

Relevant code:

pumpkin/src/world/mod.rs:3874

pub fn broadcast_entity_spawn(&self, entity: &Arc<dyn EntityBase>) {
    let players = self.players.load();

    for player in players.iter() {
        let center = player.get_entity().chunk_pos.load();
        let view_distance = get_view_distance(player).get() as i32;

        if is_within_view_distance(chunk_pos, center, view_distance) {
            player.client.try_enqueue_spawn_packet(entity);
        }
    }
}

pumpkin/src/net/mod.rs:245

pub fn try_enqueue_spawn_packet(&self, entity: &Arc<dyn EntityBase>) {
    match self {
        Self::Java(java) => {
            java.try_enqueue_packet(
                &entity.get_entity().create_spawn_packet()
            )
        }
        Self::Bedrock(bedrock) => {
            bedrock.enqueue_spawn_packet(entity.clone())
        }
    }
}

pumpkin/src/net/bedrock/mod.rs:668

pub fn enqueue_spawn_packet(
    self: &Arc<Self>,
    entity: Arc<dyn EntityBase>,
) {
    let client = self.clone();

    self.spawn_task(async move {
        entity.send_bedrock_spawn_packet(&client).await;
    });
}

pumpkin/src/net/bedrock/mod.rs:1213

Some(self.tasks.spawn(task))

The crashing thread is Gen-Pool-5, which appears to be a Rayon chunk-generation worker thread rather than a Tokio runtime thread.

Because spawn_task() eventually calls self.tasks.spawn(task) from a Gen-Pool-* thread, Tokio reports:

there is no reactor running, must be called from the context of a Tokio 1.x runtime

This suggests Bedrock spawn packets are being scheduled from chunk generation worker threads without access to a Tokio runtime.

To Reproduce

  1. Start a Pumpkin server with Bedrock support enabled.
  2. Connect using a Bedrock client.
  3. Allow chunk generation to occur (new world or unexplored chunks).
  4. Wait until chunk generation reaches the Spawn stage.
  5. Server crashes

Expected behavior

Chunk generation should complete without crashing when mobs are spawned.

Bedrock clients should receive entity spawn packets normally, and packet scheduling should not panic when chunk generation occurs on worker threads.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions