tauri: [bug] thread 'main' has overflowed its stack (Windows 11 Tauri v2 beta)

Describe the bug

Got thread 'main' has overflowed its stack error on Windows. (Also tried on Mac and Linux and there is no problem)

I was developing an app on Mac. When I try to migrate to Windows, I got this error.

I have seen the same error message in other github issues, but I don’t think it’s the same problem.

Reproduction

I made a minimum reproduction project here https://github.com/HuakunShen/tauri-win-stackoverflow

Some explanation in repo README as well.

I simply added a few official plugins, and 2 capability files.

For me the reproduction project won’t run with npm run tauri dev. But if I run rust code with release mode it will run.

pnpm dev # start frontend dev server

# in another terminal
cd src-tauri
cargo run # this still gives stack overflow error
cargo run --release # this will run

If I simply remove 3 unused plugins from Cargo.toml it will run.

If I remove some capabilities it will run.

Expected behavior

It should run.

Full tauri info output

❯ npm run tauri info

> tauri-win-stackoverflow@0.0.0 tauri
> tauri info


[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 125.0.2535.67
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.77.2 (25ef9e3d8 2024-04-09)
    ✔ cargo: 1.77.2 (e52e36006 2024-03-26)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 20.9.0
    - pnpm: 9.1.2
    - yarn: 1.22.22
    - npm: 10.5.2
    - bun: 1.1.4

[-] Packages
    - tauri [RUST]: 2.0.0-beta.20
    - tauri-build [RUST]: 2.0.0-beta.16
    - wry [RUST]: 0.40.0
    - tao [RUST]: 0.28.0
    - @tauri-apps/api [NPM]: 2.0.0-beta.12
    - @tauri-apps/cli [NPM]: 2.0.0-beta.18

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: React
    - bundler: Vite

Stack trace

❯ pnpm tauri dev

> tauri-win-stackoverflow@0.0.0 tauri C:\Users\shenh\Desktop\tauri-win-stackoverflow
> tauri "dev"

    Running BeforeDevCommand (`pnpm dev`)

> tauri-win-stackoverflow@0.0.0 dev C:\Users\shenh\Desktop\tauri-win-stackoverflow
> vite


  VITE v5.2.11  ready in 130 ms

  ➜  Local:   http://localhost:1420/
  ➜  Network: use --host to expose
    Info Watching C:\Users\shenh\Desktop\tauri-win-stackoverflow\src-tauri for changes...
   Compiling tauri-win-stackoverflow v0.0.0 (C:\Users\shenh\Desktop\tauri-win-stackoverflow\src-tauri)
error: failed to remove file `C:\Users\shenh\Desktop\tauri-win-stackoverflow\src-tauri\target\debug\tauri-win-stackoverflow.exe`

Caused by:
  Access is denied. (os error 5)
 ELIFECYCLE  Command failed with exit code 4294967295.
 ELIFECYCLE  Command failed with exit code 101

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

anybody needing an immediate solution without changing stack size parameters can use

let context = std::thread::spawn(|| tauri::generate_context!())
  .join()
  .expect("context thread");

tauri::Builder::default()
  // ... snip ...
  .run(context)
  // ... snip ...

This is because the default thread stack size is set to 2MiB on all platforms, or higher if the platform sets it higher themselves. The main thread does not default to this.

If you need even MORE stack space, you can use std::thread::Builder::new().stack_size(bytes).

The context creates a lot of things at runtime from items consumed during build time. So there are lots of heap structures created, many of which have their values on the stack before they are passed in. So they all get created at once. With the new ACL system moving to plugins (and therefore the build system and the context), there are many more values - blowing pass the 1MiB size with enough plugins in your dependencies.

I’m looking at ways to get around this.

I hit this too, in my case I just have 3 commands and some fs permissions.

I don’t think this should be closed though, it’s not normal and will leave a lot of people guessing what’s wrong. Maybe Tauri could use less stack memory by allocating more on the heap (Box)?

Makes sense, commands and plugins which are dynamically added could easily overflow the stack as the number grows. Ideally they should be allocated on heap.

I will reopen this.

I just encountered the same issue on Windows msvc.

Setting the following env before build fixed it

$env:RUSTFLAGS = "-C link-arg=/STACK:8000000"

same issue on my PC too. win11 latest

note, this doesnt fix my issue:

[target.x86_64-pc-windows-msvc]
rustflags = [
	"-C", "link-arg=/STACK:8000000"
]

# 64 bit Mingw
[target.x86_64-pc-windows-gnu]
rustflags = [
    "-C", "link-arg=-Wl,--stack,8000000"
]

How many plugins permissions and commands doyou have? Have you tried to increase the stack size beyond 8Mb? and note that the config shouldn’t be added to Cargo.toml, but config.toml