grpc / grpc/grpc-rust

Remove default `fallback` in tonic::service::Routes;

Open
#1,955 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

## Feature Request
### Motivation

Sorry for raising this issue if I missed some info.
Can't use tonic Routes with axum router with its own fallback:
`Cannot merge two `Router`s that both have a fallback`. This is an axum error, but it appears that tonic Routes by default set fallback:
https://github.com/hyperium/tonic/blob/6d93c1d0c1a593a5e5476d9c47a1016748acbb5f/tonic/src/service/router.rs#L54

As a result in example like this you receive an error, then have to find where another fallback comes from so to overwrite it or if you don'y use any fallback you get one from tonic Routes for all of your handlers which might be unexpected or not very obvious.
```rust
async fn hello() -> impl axum::response::IntoResponse {
"Hello, World!"
}

async fn im_a_teapot() -> impl axum::response::IntoResponse {
(StatusCode::IM_A_TEAPOT, "IM_A_TEAPOT")
}

#[tokio::main]
async fn main() {
let app = Router::new().route("/hello", get(hello));
// .fallback(im_a_teapot); <--- if added will fail in runtime.

let tonic_routes = Routes::new(EchoServer::new(MyEcho)).into_axum_router();
let app = app.merge(tonic_routes);

let listener = tokio::net::TcpListener::bind("127.0.0.1:8000")
.await
.unwrap();

axum::serve(listener, app).await.unwrap();
}
```

### Proposal

Remove default fallback from:
https://github.com/hyperium/tonic/blob/6d93c1d0c1a593a5e5476d9c47a1016748acbb5f/tonic/src/service/router.rs#L54
### Alternatives

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.