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

Memory leak in leptos_router #2514

Closed
akarras opened this issue Apr 10, 2024 · 2 comments
Closed

Memory leak in leptos_router #2514

akarras opened this issue Apr 10, 2024 · 2 comments

Comments

@akarras
Copy link
Contributor

akarras commented Apr 10, 2024

Describe the bug
I am observing a memory leak in my leptos app, and am trying to profile it. During profiling, I observed create_branches seemingly allocating 2GB after a short load test. I think that router.id() isn't stable and leads to the cached branches to grow over time

Adding a good ol' error log to the router it does indeed seem to increment with each request.

024-04-10T03:51:52.607810Z ERROR leptos_router::components::routes: ROUTER ID 6929 base: 
2024-04-10T03:51:52.607868Z ERROR leptos_router::components::routes: ROUTER ID 6928 base: 
2024-04-10T03:51:52.608229Z ERROR leptos_router::components::routes: ROUTER ID 6930 base: 
2024-04-10T03:51:52.608423Z ERROR leptos_router::components::routes: ROUTER ID 6931 base: 
2024-04-10T03:51:52.608799Z ERROR leptos_router::components::routes: ROUTER ID 6932 base: 
2024-04-10T03:51:52.610152Z ERROR leptos_router::components::routes: ROUTER ID 6933 base: 
2024-04-10T03:51:52.612869Z ERROR leptos_router::components::routes: ROUTER ID 6934 base: 
2024-04-10T03:51:52.613191Z ERROR leptos_router::components::routes: ROUTER ID 6935 base: 

Leptos Dependencies

leptos = { version = "0.6.10", default-features = false, features = [
  "serde",
  "nightly"
] }
leptos_axum = { version = "0.6.10" }
leptos_router = { version = "0.6.10", default-features = false, features = ["nightly"] }
leptos_meta = { version = "0.6.10", default-features = false, features = ["nightly"] }

To Reproduce
Steps to reproduce the behavior:

  1. Launch an axum example application and load test
  2. Watch the memory over time

Expected behavior
Branches to not leak memory

Screenshots
Screenshot of create_branches apparently allocating 2.1GB
firefox_qaIzeJG3rt

Additional context
Testing with the router_id hard coded to 0 does indeed seem to prevent the leak, but I am not sure what the best solution is to ensure users can continue to use multiple routers in their app and decided to open up an issue instead of a pull request 😄

gbj added a commit that referenced this issue Apr 10, 2024
@gbj
Copy link
Collaborator

gbj commented Apr 10, 2024

Yikes!

Can you check PR #2515 to see if it resolves the issue you're measuring?

cc @sbihel For your use case of mounting multiple apps with different routers you will just need to introduce an id=0, id=1 etc. prop on <Router/>. In #2135 to fix #1806 I did not think about the fact that of course the Router ID would be new on each request, creating an infinitely growing HashMap.

@gbj gbj closed this as completed in e68f1bb Apr 10, 2024
@akarras
Copy link
Contributor Author

akarras commented Apr 10, 2024

I see you've already published, but yes I can confirm that seems to resolve my issue! Thank you very much 😄

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

2 participants