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

set_interval_with_handle callback doesn't resolve a borrowed reference of a RefCell during panic #3072

Open
mxgordon opened this issue Oct 8, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@mxgordon
Copy link

mxgordon commented Oct 8, 2024

Describe the bug
A clear and concise description of what the bug is.
When a panic occurs within the set_interval_with_handle callback and there is a RefCell that has been borrowed. The borrowed RefCell isn't resolved, so when the interval callback runs again, it throws a "already borrowed: BorrowMutError".

Leptos Dependencies

[dependencies]
leptos = { version = "0.6", features = ["csr", "nightly"] }
leptos_meta = { version = "0.6", features = ["csr", "nightly"] }
leptos_router = { version = "0.6", features = ["csr", "nightly"] }
console_log = "1"
log = "0.4"
console_error_panic_hook = "0.1"

To Reproduce
Steps to reproduce the behavior:

  1. Create an interval callback that panics after calling {RefCell}.borrow_mut()
  2. Check the console log and it will have a secondary error from trying to make that borrow again

Expected behavior
This may be expected behavior; however, I can't imagine why as it makes debugging more difficult because it will keep repeating the borrow error and it makes it hard to debug the original error that caused the problem.

@gbj
Copy link
Collaborator

gbj commented Oct 8, 2024

There is no way that I'm aware of to gracefully recover from panics in WASM, which means that if you cause a panic in user-land code there is no way for the framework to do things like unregister any timers or even listeners that have been registered.

(Unless I'm misunderstanding what you're saying, in which case: please provide a reproducible example.)

@mxgordon
Copy link
Author

mxgordon commented Oct 8, 2024

No, sounds like you got it. In that case, is this documented somewhere? Because I would categorize this as unexpected behavior and I think it should be mentioned somewhere in the docs for set_interval_with_handle/set_interval.

@gbj
Copy link
Collaborator

gbj commented Oct 8, 2024

I do not know if this is documented somewhere. I learned it somewhere in my last few years of working with Rust/WASM. If you Google "Rust WASM panic" you can find plenty of discussion of the above but I don't see an obvious place in Rust docs. A very good description of basically what you describe above is found in this StackOverflow post.

Feel free to make a PR for the docs for set_interval... saying that panics in the handler will not cancel the interval, and that panics in general in WASM are not recoverable and there is no coherent way to respond to them short of reloading the page.

@gbj gbj added the documentation Improvements or additions to documentation label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants