-
Notifications
You must be signed in to change notification settings - Fork 156
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
Use-after-free with create_effect #602
Comments
Yikes. I'm not sure if it's possible to fix this without severely limiting the power of the reactivity system. I'm starting to think that perhaps the whole lifetime gymnastics was a mistake to begin with and that the idea is fundamentally inconsistent with how lifetimes work in Rust. Fixing this will unfortunately mean we'll probably have to make some pretty invasive changes to reactivity. I think the options are as follows:
As for whether 3. will make Sycamore too similar to Leptos, I don't think it's too big of an issue because whereas Leptos seems to be more web-focused right now, I intend Sycamore to be a more general UI framework that supports not just web but also potentially native and TUI in the future. |
I think option 3 is by far the most preferable. I don't think copying leptos is a problem in the first place, and sycamore's much more pleasant to work with view syntax (in my opinion) still makes it stand out. I've also spent a lot of time writing library code for sycamore and while the lifetimes are a nice touch in theory they become an ergonomic nightmare once you start passing around signals or storing them in structs. |
Just to put in my two cents re: Option 3: I think if you want to go this route, you should consider whether using This would unlock a lot of possibilities, like the two communities collaborating on a (We did the same thing so that Dioxus and Leptos could share the same server function code. One of the things I love above the Rust community vs. JS is the tendency to coalesce around a smaller number of shared, primitive crates.) It should go without saying given the MIT license and nature of open source but if you want to go Option 3 without collaborating so directly, of course feel free to use whatever parts of Leptos code make sense to use. While I don't think there's really anything left in Leptos at this point that has a direct lineage from Sycamore, Sycamore was a huge source for me to learn how to implement the SolidJS approach in Rust originally, and I have a huge amount of respect for you and your work on it! |
Thanks for the kind words @gbj! Your work on Leptos is awesome and it's great to see Rust WASM becoming more and more widespread! I think for now I would rather keep the two implementations separate just for flexibility's sake. This way, we can iterate quickly on both sides without trying to coordinate changes between the two frameworks. I spent quite a bit of time looking at the Leptos implementation of reactivity and the index solution is quite clever and clean! It definitely looks nothing like the tangled lifetime mess I've gotten myself into here. The lineage of these Rust UI frameworks is definitely very interesting. Originally, I created Sycamore based on Yew's new functional components (back when struct components were still the default), combined with the reactive system from SolidJS. However, this brought over the all the |
Also on the topic of removing The idea was actually surprisingly similar to the index approach although I did not think of using a global However, with the current architecture that the Leptos reactive system uses, I believe this could actually work pretty well. Hopefully you'll have more luck than I had if you do decide to go down this route! |
I'll just add that I believe |
Is it not possible to ensure that all effects are dropped before everything in the arena? |
Yes I that's a possible solution as well which I completely missed, although the more I think about it, the more I'm quite inclined to move to an index based approach instead. |
Describe the bug
This is not always true, the FnMut() might own some type that accesses the Scope in it's drop implementation, which could lead to use-after-free.
Environment
The text was updated successfully, but these errors were encountered: