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

spawn_local panic within generate_route_list using axum #1775

Closed
akarras opened this issue Sep 23, 2023 · 5 comments · Fixed by #1777
Closed

spawn_local panic within generate_route_list using axum #1775

akarras opened this issue Sep 23, 2023 · 5 comments · Fixed by #1777
Labels
bug Something isn't working

Comments

@akarras
Copy link
Contributor

akarras commented Sep 23, 2023

Describe the bug

Getting a panic when calling generate_route_list after updating on latest main. Still investigating exact cause

Full stack trace

`spawn_local` called from outside of a `task::LocalSet`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/panicking.rs:619:5
   1: core::panicking::panic_fmt
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/core/src/panicking.rs:72:14
   2: tokio::task::local::spawn_local_inner
             at /Users/aaronkarras/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/task/local.rs:347:21
   3: tokio::task::local::spawn_local
             at /Users/aaronkarras/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.32.0/src/task/local.rs:337:9
   4: leptos_reactive::spawn::spawn_local
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/spawn.rs:87:13
   5: leptos_reactive::resource::ResourceState<S,T>::load::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:1323:13
   6: leptos_reactive::memo::forward_ref_to::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/memo.rs:258:9
   7: leptos_reactive::signal::<impl leptos_reactive::node::NodeId>::try_with_no_subscription
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/signal.rs:2041:12
   8: <leptos_reactive::memo::Memo<T> as leptos_reactive::signal::SignalWith>::try_with::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/memo.rs:472:13
   9: leptos_reactive::runtime::with_runtime::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:697:41
  10: std::thread::local::LocalKey<T>::try_with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:270:16
  11: std::thread::local::LocalKey<T>::with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:246:9
  12: leptos_reactive::runtime::with_runtime
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:693:13
  13: <leptos_reactive::memo::Memo<T> as leptos_reactive::signal::SignalWith>::try_with
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/memo.rs:470:9
  14: leptos_reactive::resource::ResourceState<S,T>::load
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:1295:13
  15: leptos_reactive::resource::create_local_resource_with_initial_value::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:365:18
  16: <leptos_reactive::effect::EffectState<T,F> as leptos_reactive::effect::AnyComputation>::run
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/effect.rs:366:25
  17: leptos_reactive::runtime::Runtime::update::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:230:25
  18: leptos_reactive::runtime::Runtime::with_observer
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:328:17
  19: leptos_reactive::runtime::Runtime::update
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:226:21
  20: leptos_reactive::runtime::Runtime::update_if_necessary
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:186:13
  21: leptos_reactive::effect::create_isomorphic_effect::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/effect.rs:256:9
  22: leptos_reactive::runtime::with_runtime::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:697:41
  23: std::thread::local::LocalKey<T>::try_with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:270:16
  24: std::thread::local::LocalKey<T>::with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:246:9
  25: leptos_reactive::runtime::with_runtime
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:693:13
  26: leptos_reactive::effect::create_isomorphic_effect
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/effect.rs:255:9
  27: leptos_reactive::resource::create_local_resource_with_initial_value
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:361:5
  28: leptos_reactive::resource::create_local_resource
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:296:5
  29: ultros_app::global_state::cheapest_prices::CheapestPrices::new
             at ./ultros-frontend/ultros-app/src/global_state/cheapest_prices.rs:21:29
  30: ultros_app::App::__App
             at ./ultros-frontend/ultros-app/src/lib.rs:35:21
  31: ultros_app::App::{{closure}}
             at ./ultros-frontend/ultros-app/src/lib.rs:29:1
  32: <leptos_dom::components::Component<F,V> as leptos_dom::IntoView>::into_view::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_dom/src/components.rs:281:49
  33: leptos_reactive::runtime::RuntimeId::untrack::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:926:32
  34: leptos_reactive::runtime::with_runtime::{{closure}}
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:697:41
  35: std::thread::local::LocalKey<T>::try_with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:270:16
  36: std::thread::local::LocalKey<T>::with
             at /rustc/030e4d382f1df30240408540f25cd1ccc8dbbf50/library/std/src/thread/local.rs:246:9
  37: leptos_reactive::runtime::with_runtime
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:693:13
  38: leptos_reactive::runtime::RuntimeId::untrack
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:913:9
  39: leptos_reactive::runtime::untrack_with_diagnostics
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/runtime.rs:1470:5
  40: <leptos_dom::components::Component<F,V> as leptos_dom::IntoView>::into_view
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_dom/src/components.rs:281:21
  41: <Func as leptos::ComponentConstructor<P>>::construct
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos/src/lib.rs:346:9
  42: leptos::component_view
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos/src/lib.rs:321:5
  43: ultros::leptos::create_leptos_app::{{closure}}::{{closure}}
             at ./ultros/src/leptos.rs:72:9
  44: leptos_router::extract_routes::generate_route_list_inner
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/router/src/extract_routes.rs:126:9
  45: leptos_axum::generate_route_list_with_exclusions_and_ssg
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/integrations/axum/src/lib.rs:1259:9
  46: leptos_axum::generate_route_list
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/integrations/axum/src/lib.rs:1215:5

Leptos Dependencies

leptos = { git = "https://github.com/leptos-rs/leptos.git", default-features = false, features = [
  "serde",
  "nightly"
] }
leptos_axum = { git = "https://github.com/leptos-rs/leptos.git" }
leptos_router = { git = "https://github.com/leptos-rs/leptos.git", default-features = false, features = ["nightly"] }
leptos_meta = { git = "https://github.com/leptos-rs/leptos.git", default-features = false, features = ["nightly"] }

No MRE yet: It looks like updates to static site generation 3b864ac is triggering it. Reverting to the commit prior resolves the error.

This sort of makes sense- in the rest of the axum integrations we use the thread pool trick to be able to use LocalKeys. We could probably reuse this trick, or reevaluate whether we want generating a route list to invoke static generation or not.

@gbj
Copy link
Collaborator

gbj commented Sep 23, 2023

Are you calling spawn_local itself during rendering somewhere rather than using a resource?

@gbj
Copy link
Collaborator

gbj commented Sep 23, 2023

Never mind, looking at the stack trace it looks like it's a resource. I'll look into it a bit. These are supposed to be suppressed during route list generation.

@gbj
Copy link
Collaborator

gbj commented Sep 23, 2023

Here's the relevant part of the stacktrace.

  28: leptos_reactive::resource::create_local_resource
             at /Users/aaronkarras/.cargo/git/checkouts/leptos-2c8932a5258b3db6/d99269a/leptos_reactive/src/resource.rs:296:5
  29: ultros_app::global_state::cheapest_prices::CheapestPrices::new
             at ./ultros-frontend/ultros-app/src/global_state/cheapest_prices.rs:21:29

i.e., it's the local resource created at src/global_state/cheapest_prices.rs:21:29 that is causing the issue. Local resources really don't need to run on the server anyway... Let me know if #1777 fixes this issue.

@gbj gbj added the bug Something isn't working label Sep 23, 2023
@sbihel
Copy link
Contributor

sbihel commented Sep 23, 2023

I believe I had the same issue, trying to do "conditional" routes, and it's working as expected now. Thank you

@akarras
Copy link
Contributor Author

akarras commented Sep 23, 2023

Yep, #1777 fixes the issue! Love it, open an issue, go to sleep, and then @gbj fixes things. Thanks 😄

@gbj gbj closed this as completed in #1777 Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants