SoftbearStudios / mk48

Mk48.io ship combat game
https://mk48.io
GNU Affero General Public License v3.0
314 stars 60 forks source link

Running the Server in debug crashes with stack overflow #214

Open MindSwipe opened 1 year ago

MindSwipe commented 1 year ago

Describe the bug

Running make in the server directory doesn't work on Windows, so I copy and pasted the command that make would run into the terminal and ran that, so:

cargo run -- --debug-core debug --max-bots 0 --database-read-only --http-port

8081

This spits out a bunch of info logs, and one error log

[ERROR game_server::entry_point] could not set open file limit: unsupported OS

alongside the referrer snippet for cohort none, and then just

thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\debug\server.exe --max-bots 0 --database-read-only --http-port 8081` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

Expected behavior

I expect the server to start and run.

Additional context (optional)

Running the server in release mode

cargo run --release -- --debug-core debug --max-bots 0 --database-read-only --http-port  8081

Works

finnbear commented 1 year ago

Thanks for the issue! You can safely ignore the open file warning, unless you plan to host a web-facing server on Windows. The stack overflow is probably because Rust compiles relatively inefficient code in debug mode and the default stack size in windows is smaller. In the next update, I can introduce some code to request a larger stack for the main thread when running in debug mode.

fn expand_stack(
    fut: impl Future<Output = Result<(), Error>> + Send + 'static,
) -> Result<(), Error> {
    #[allow(unused_mut)]
    let mut builder = Builder::new();

    #[cfg(debug_assertions)]
    {
        builder = builder.stack_size(12_000_000);
    }

    builder
        .spawn(|| {
            let runtime = tokio::runtime::Builder::new_current_thread().build().unwrap();
            runtime.block_on(fut)
        })
        .unwrap()
        .join()
        .unwrap()
}