Skip to content
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

Stack overflow in while loop inside async #93

Closed
danarmak opened this issue Nov 15, 2014 · 2 comments
Closed

Stack overflow in while loop inside async #93

danarmak opened this issue Nov 15, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@danarmak
Copy link

This code causes a stack overflow:

async {
  while (true) {
    if (false) {
      await(Future.successful(()))
    }
  }
}

The generated resume method takes up a stack frame for each iteration of the loop.

Tested with 0.9.2 for scala 2.10. Has this been fixed in the master branch? I don't have time to check at the moment.

@retronym
Copy link
Member

Thanks for the report. I believe we can avoid the apply/resume stack growth easily enough. I started working on a patch but haven't quite got it working yet. Just letting you know this is still on my radar...

@retronym retronym self-assigned this Dec 10, 2014
@retronym retronym added this to the 0.9.3 milestone Dec 10, 2014
@retronym retronym added the bug label Dec 10, 2014
retronym added a commit to retronym/async that referenced this issue Dec 15, 2014
Previously, as sequence of state transitions that did not pass through
an asynchrous boundary incurred stack frames. The trivial loop in
the enclosed test case would then overflow the stack.

This commit merges the `resume` and `apply(tr: Try[Any])` methods into
a `apply`. It changes the body of this method to be an infinite loop
with returns at the terminal points in the state machine (or at a
terminal failure.)

To allow merging of these previously separate matches, states that
contain an await are now allocated two state ids: one for the setup
code that calls `onComplete`, and one for the code in the continuation
that records the result and advances the state machine.

Fixes scala#93
@danarmak
Copy link
Author

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants