Skip to content

stack overflow while compiling async recursion #140725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ehaydenr opened this issue May 6, 2025 · 2 comments
Open

stack overflow while compiling async recursion #140725

ehaydenr opened this issue May 6, 2025 · 2 comments
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehaydenr
Copy link

ehaydenr commented May 6, 2025

Compiler encounters segfault when compiling the below code

Code

struct Wrapper<T>(T);

pub async fn f1() {
    f2(Wrapper(())).await
}

pub async fn f2<T>(stream: T) {
    Box::pin(f2(Wrapper(stream))).await
}

Meta

$ cargo version
cargo 1.86.0 (adf9b6ad1 2025-02-28)
$ cargo +nightly version
cargo 1.88.0-nightly (7918c7eb5 2025-04-27)

Error output

Stable

error: rustc interrupted by SIGSEGV, printing backtrace

/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x2fa1b74)[0xffffaf891b74]
linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0xffffb09f17ac]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(_RNvNtNtCs1eHWH1cD26q_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x26c)[0xffffade124c8]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(_RNvNtNtCs1eHWH1cD26q_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x164)[0xffffade123c0]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151d7f8)[0xffffade0d7f8]

### cycle encountered after 5 frames with period 6
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
### recursed 41 times

/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]
/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/lib/librustc_driver-d10e1ea80d090031.so(+0x151cf78)[0xffffade0cf78]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
note: backtrace dumped due to SIGSEGV! resuming signal
error: could not compile `segfault` (lib)

Caused by:
  process didn't exit successfully: `/usr/local/rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin/rustc --crate-name segfault --edition=2024 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=310 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=d1c27d02b862a57e -C extra-filename=-f2d1ad9e2f73cb97 --out-dir /workspaces/rust/segfault/target/debug/deps -C incremental=/workspaces/rust/segfault/target/debug/incremental -L dependency=/workspaces/rust/segfault/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)

Nightly

error: rustc interrupted by SIGSEGV, printing backtrace

/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x31b2310)[0xffffb5ef2310]
linux-vdso.so.1(__kernel_rt_sigreturn+0x0)[0xffffb714e7ac]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(_RNvNtNtCsiqNB9qq6D9S_17rustc_codegen_ssa9debuginfo10type_names14push_item_name+0x4)[0xffffb4543080]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fe368)[0xffffb453e368]

### cycle encountered after 4 frames with period 5
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
### recursed 50 times

/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]
/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/librustc_driver-121983e25d0fab07.so(+0x17fd8f0)[0xffffb453d8f0]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
error: could not compile `segfault` (lib)

Caused by:
  process didn't exit successfully: `/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-gnu/bin/rustc --crate-name segfault --edition=2024 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=310 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=6efcc8920530f666 -C extra-filename=-ca85f3463d939f74 --out-dir /workspaces/rust/segfault/target/debug/deps -C incremental=/workspaces/rust/segfault/target/debug/incremental -L dependency=/workspaces/rust/segfault/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)
@ehaydenr ehaydenr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2025
@workingjubilee
Copy link
Member

huh, some obvious recursion but otherwise I think that's a genuinely novel report. fascinating! thanks!

@workingjubilee workingjubilee changed the title rustc unexpectedly overflowed its stack! stack overflow while compiling async recursion May 6, 2025
@workingjubilee workingjubilee added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-async-await Area: Async & Await I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 6, 2025
@moxian
Copy link
Contributor

moxian commented May 7, 2025

rustc printed a nice error message prior to nightly-2024-01-10 (1.77.0):

error[E0733]: recursion in an `async fn` requires boxing
 --> src\lib.rs:7:1
  |
7 | pub async fn f2<T>(stream: T) {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive `async fn`
  |
  = note: a recursive `async fn` must be rewritten to return a boxed `dyn Future`
  = note: consider using the `async_recursion` crate: https://crates.io/crates/async_recursion

For more information about this error, try `rustc --explain E0733`.
error: could not compile `mycrate` (lib) due to 1 previous error
PRs in nightly-2024-01-10
PRs in range:
  - #119606 (Consuming `emit`) by nnethercote
  - #119754 (Rollup of 10 pull requests) by matthiaskrgr
    - #118903 (Improved support of collapse_debuginfo attribute for macros.)
    - #119033 (coverage: `llvm-cov` expects column numbers to be bytes, not code points)
    - #119598 (Fix a typo in core::ops::Deref's doc)
    - #119660 (remove an unnecessary stderr-per-bitwidth)
    - #119663 (tests: Normalize `\r\n` to `\n` in some run-make tests)
    - #119681 (coverage: Anonymize line numbers in branch views)
    - #119704 (Fix two variable binding issues in lint let_underscore)
    - #119725 (Add helper for when we want to know if an item has a host param)
    - #119738 (Add `riscv32imafc-esp-espidf` tier 3 target for the ESP32-P4.)
    - #119740 (Remove crossbeam-channel)
  - #119732 (Subtree update of `rust-analyzer`) by lnicola
  - #119760 (Rollup of 7 pull requests) by matthiaskrgr
    - #117744 (Add -Zuse-sync-unwind)
    - #118649 (Make inductive cycles in coherence ambiguous always)
    - #118979 (Use `assert_unsafe_precondition` for `char::from_u32_unchecked`)
    - #119619 (mir-opt and custom target fixes)
    - #119632 (Fix broken build for ESP IDF due to #119026)
    - #119712 (Adding alignment to the cases to test for specific error messages.)
    - #119734 (Miri subtree update)
  - #117703 (Support async recursive calls (as long as they have indirection)) by compiler-errors
  - #118968 (unify query canonicalization mode) by aliemjay
  - #119767 (Rollup of 9 pull requests) by GuillaumeGomez
    - #117556 (Disallow reference to `static mut` and adding `static_mut_ref` lint)
    - #118748 (std: getrandom simplification for freebsd.)
    - #119282 (Rework and improve the unstable documentation of check-cfg)
    - #119527 (don't reexport atomic::ordering via rustc_data_structures, use std import)
    - #119668 (Simplify implementation of MIR promotion)
    - #119699 (Merge dead bb pruning and unreachable bb deduplication.)
    - #119723 (Remove `-Zdont-buffer-diagnostics`.)
    - #119756 (rustdoc-search: reuse individual types in function signatures)
    - #119758 (GNU/Hurd: unconditionally use inline stack probes)
  - #119777 (Rollup of 5 pull requests) by GuillaumeGomez
    - #118241 (Making `User<T>` and `User<[T]>` `Send`)
    - #118645 (chore: Bump compiler_builtins)
    - #118680 (Add support for shell argfiles)
    - #119721 (`~const` trait and projection bounds do not imply their non-const counterparts)
    - #119768 (core: panic: fix broken link)
  - #116846 (A more efficient slice comparison implementation for T: !BytewiseEq) by krtab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants