-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
stack overflow if router been .boxed
for more than 281 times
#392
Comments
Uh thats an interesting bug. I did some digging and it only seems to happen if you're running the router with hyper. If you use axum::body::Body;
use axum::handler::get;
use axum::http::Request;
use axum::routing::{BoxRoute, Router};
use tower::{Service, ServiceExt};
#[tokio::main]
async fn main() {
let mut app = get_router();
for uri in ["/get1", "/get281"] {
let res = app
.ready()
.await
.unwrap()
.call(Request::builder().uri(uri).body(Body::empty()).unwrap())
.await
.unwrap();
dbg!(&res);
}
}
fn get_router() -> Router<BoxRoute> {
let mut router = Router::new().boxed();
for i in 0..282 {
router = router
.route(
&format!("/get{}", i),
get(move || async move { format!("i = {}", i) }),
)
.boxed();
}
router
} I don't really know how to go about debugging this. @jplatte any ideas? While I think this is something that should be fixed I'm also getting the impression that you're boxing all of your routes. That really isn't recommended. You should rather make logical groups of routes, box those, and combine them either with |
@davidpdrsn BTW, if you set
It looks like there is a positive correlation between the number of times of this log message and the number of routes. |
.boxed
for more than 282 times.boxed
for more than 282 times
.boxed
for more than 282 times.boxed
for more than 281 times
Have you tried the workaround I mention in #200 (comment)? With that boxing once should work. |
It will perform really badly(I guess This and this pull request is probably needed for acceptable performance. Even then I wouldn't expect much performance(maybe |
Yes, I fixed it with |
Bug Report
Version
0.2.8
Platform
Windows x64 msvc
macOS
Description
I'm migrating a large project from rocket to axum
I want to keep the route configurations (path, params) close to the route functions, so for each module I have a function called
register_routes
which looks like this:then in the
main
I have a function to call allregister_routes
.This worked well until the number of the routes reach a certain amount: axum crashes with
Then I found out that if the number of routes passes 282, axum will crash:
Here is the reproduction:
https://github.com/fluxxu/axum-stack-overflow
The text was updated successfully, but these errors were encountered: