Skip to content

Possible stack overflow using await! inside generator #1330

Closed
@realcr

Description

@realcr

Hi, I am dealing with a stack overflow issue in my code when using futures-preview = "0.3.0-alpha.9". I believe that it might be related to the futures crate. Unfortunately I could not reproduce this using a minimal example.

I am using rustc 1.32.0-nightly (65204a97d 2018-11-12), my other dependencies are:
log, pretty_env_logger, untrusted, bytes, futures-cpupool, futures-preview, num-biginit, num-traits, serde, serde-derive, serde-json, base64, atomicwrites, im, byteorder, ring, rand.
I have no unsafe {} clauses in my code. The stack overflow occurs in one test case in my code.

The test case contains the following two lines (Inside an async function):

loop {} // I added this line for debugging purposes
let (outgoing_comms, _outgoing_control) = await!(apply_funder_incoming(funder_incoming, &mut state2, &mut ephemeral2, 
                                 rng.clone(), identity_client2.clone())).unwrap();

The code compiles successfully. When run, it is stuck in an infinite loop. However, if the loop {} is moved after the await!() line, I get a stack overflow:

$ cargo test -p offst-funder handler_pair
   Compiling offst-funder v0.1.0 (/home/real/projects/d/offst/components/funder)

    Finished dev [unoptimized + debuginfo] target(s) in 5.14s
     Running target/debug/deps/offst_funder-2301b5d9d090c072

running 1 test

thread 'handler::tests::test_handler_pair_basic' has overflowed its stack
fatal runtime error: stack overflow
error: process didn't exit successfully: `/home/real/projects/d/offst/target/debug/deps/offst_funder-2301b5d9d090c072 handler_pair` (signal: 6, SIGABRT: process abort signal)

Therefore I believe that the stack overflow occurs when the await!() statement is executed.

I also noticed that if I split the await!() line to two lines (with a temporary fut variable):

loop {}
let fut = apply_funder_incoming(funder_incoming, &mut state2, &mut ephemeral2, 
                                 rng.clone(), identity_client2.clone());
let (outgoing_comms, _outgoing_control) = await!(fut).unwrap();

A stack overflow occurs. This probably means that it happens before the loop {} line in this case. The fact that the stack overflow changes its place makes me believe it might be related to the generator that contains the async code, though I'm not sure about it.

The full code is here: freedomlayer/offset@876ddf3
The stack overflow occurs at the test_handler_pair_basic test case.

To reproduce, run the following:

sudo apt install capnproto
git clone https://github.com/freedomlayer/offst
cd offst
git checkout 876ddf389
rustup override set nightly-2018-11-13
cargo test -p offst-funder test_handler_pair_basic

I realize that you might not have the time to check this issue, because the reproducing example is very large. In such a case, is there anything I can do to help solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions