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

How to catch stack overflow? #141

Closed
alexcrichton opened this issue Apr 18, 2018 · 9 comments
Closed

How to catch stack overflow? #141

alexcrichton opened this issue Apr 18, 2018 · 9 comments

Comments

@alexcrichton
Copy link
Contributor

Occasionally from time to time you'll accidentally write a deeply recursive function which blows the stack. Ideally this is caught and identified immediately, but sometimes a stack overflow can cause crazy corruption throughout the system and be otherwise very hard to debug.

Currently there's no mechanism for catching a stack overflow with wasm, and a stack overflow ends up corrupting the globals section most likely (oh dear!).

@Diggsey
Copy link

Diggsey commented Apr 19, 2018

I think we might have run into this with stdweb... https://github.com/benkonz/texture_issue/pull/1#issuecomment-382498172

@sendilkumarn
Copy link
Member

yes it would be awesome to know how to debug this thing

@CryZe
Copy link

CryZe commented Apr 19, 2018

Maybe Rust could have a special compiler flag that introduces additional stack overflow checks and panics if it detects one.

@pepyakin
Copy link
Member

@CryZe Yeah, that's definitely a good idea, even if it would be opt-out.

@fitzgen
Copy link
Member

fitzgen commented Apr 19, 2018

I think we should change the memory layout constructed by lld, as described in https://github.com/rust-lang-nursery/rust-wasm/issues/81#issuecomment-382880848

@alexcrichton
Copy link
Contributor Author

Yeah I do think that it's probably best to just change the default layout at this time. One unfortunate part is that it's still not easy to diagnose (a "segfault" and stack overflow look exactly the same). I think the only way we could handle that currently, though, would be to add a condition on all function calls that checks the current stack pointer (which may have a perf hit)

@alexcrichton
Copy link
Contributor Author

I believe this was covered by --stack-first in LLD on https://github.com/rust-lang-nursery/rust-wasm/issues/81

@pjtatlow
Copy link

Hey guys! I've been struggling with trying to detect (in JS) when a stack overflow occurs in my rust code (wasm). I see this issue has been closed for a while, but I'm not sure how to fix this myself. I'm hoping to be able to know when this happens, as well as when Exceptions like this happen:

Uncaught (in promise) RuntimeError: memory access out of bounds

Is this possible or no? Currently the promise that is returned from WASM just never resolves, which leaves the user spinning forever. Any ideas?

@alecmocatta
Copy link

@pjtatlow window.addEventListener('unhandledrejection', (event) => { ... }) works to catch such exceptions for me in Firefox and Safari, though it doesn't work in Chrome or Edge. See rustwasm/wasm-bindgen#2392 for more details.

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

No branches or pull requests

8 participants