rust-lang / rust-lang/rust

nightly: #[feature(async_drop)] causes stack overflow

Open
#150,609 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-await C-bug F-async_drop needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

https://github.com/JakubKoralewski/repro-rust-asyncdrop-stack-overflow/blob/main/src/main.rs

I expected to see this happen:
no error

Instead, this happened:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
     Running `/mnt/vol/.cargo/target/debug/async-drop-stack-overflow-repro`
1889328 (1845 KB)

thread 'main' (3359453) has overflowed its stack
fatal runtime error: stack overflow, aborting
Aborted (core dumped)

Just adding the feature at the top of the file causes the stack overflow. It's not necessary to even implement Drop/AsyncDrop.

Massaging this line :
let mut x = [ 0; 30 * 1024];
1889296 (1845 KB)

into 20*1024 fixes it:
1807376 (1765 KB)
1
1
1

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.94.0-nightly (56f24e00c 2025-12-29)
binary: rustc
commit-hash: 56f24e00c62ec2db9a8b407e7aef532caaf71062
commit-date: 2025-12-29
host: aarch64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Edit

I think causes may be an overstatement. I must have had an already large async fn call tree, and AsyncDrop seems to add a little bit more to the stack size and probably was the straw that broke the camels back.

I can't reproduce this particular behavior in the reproduction, but I've been trying to keep AsyncDrop in my original code, and started calling .boxed(), .boxed_local() on some futures, removing some SmallVecs to Vecs, but even then I couldn't get it to work :/ Even added a new error to the collection:

Caused by:
  process didn't exit successfully: `/mnt/vol/.cargo/target/debug/deps/single_step-8ac7d03d04480459 test_data_run_all_single_step --exact --show-output --nocapture` (signal: 7, SIGBUS: access to undefined memory)

I've seen SIGSEGV before as the first step of the stack overflow, but this is new. (error disappers when I disable AsyncDrop)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction at src/main.rs and run it using rustc 1.94.0-nightly (56f24e00c). Compare behavior with and without #[feature(async_drop)] and with the reported array sizes, then investigate the AsyncDrop-related stack growth and SIGBUS or stack-overflow failure. Done means the cause is isolated and a verified fix or regression coverage is identified.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.