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

into_make_service_with_connect_info not compile anymore #3056

Closed
1 task done
ttys3 opened this issue Dec 1, 2024 · 1 comment · Fixed by #3059
Closed
1 task done

into_make_service_with_connect_info not compile anymore #3056

ttys3 opened this issue Dec 1, 2024 · 1 comment · Fixed by #3059

Comments

@ttys3
Copy link
Contributor

ttys3 commented Dec 1, 2024

after this PR #2941

with tap_io called on listener,

axum::serve(listener, app.into_make_service_with_connect_info::<SocketAddr>()).await.unwrap(); not compile anymore

if comment out the tap_io call, it will pass the compilation

        /*.tap_io(|tcp_stream| {
            if let Err(err) = tcp_stream.set_nodelay(true) {
                eprintln!("failed to set TCP_NODELAY on incoming connection: {err:#}");
            }
        })*/;
  • I have looked for existing issues (including closed) about this

Bug Report

Version

main branch

Platform

linux

Crates

Description

I tried this code:

use axum::{response::Html, routing::get, Router};
use axum::extract::connect_info::ConnectInfo;
use axum::serve::ListenerExt;
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    // build our application with a route
    let app = Router::new().route("/", get(handler));

    // run it
    let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
        .await
        .unwrap();
    println!("listening on {}", listener.local_addr().unwrap());

    let listener = listener
        .tap_io(|tcp_stream| {
            if let Err(err) = tcp_stream.set_nodelay(true) {
                eprintln!("failed to set TCP_NODELAY on incoming connection: {err:#}");
            }
        });

    axum::serve(listener, app.into_make_service_with_connect_info::<SocketAddr>()).await.unwrap();
}

async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> Html<String> {
    Html(format!("<h1>Hello, World! {}</h1>", addr))
}

cargo

[package]
name = "axum-connection-info"
version = "0.1.0"
edition = "2021"

[dependencies]
axum = { git = "https://github.com/tokio-rs/axum", branch = "main" }
tokio = { version = "1.41.1", features = ["full"] }

92 | pub fn serve<L, M, S>(listener: L, make_service: M) -> Serve<L, M, S>
| ----- required by a bound in this function
...
95 | M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in serve

error[E0277]: Serve<TapIo<TcpListener, {closure@main.rs:18:17}>, IntoMakeServiceWithConnectInfo<..., ...>, ...> is not a future
--> src/main.rs:24:84
|
24 | axum::serve(listener, app.into_make_service_with_connect_info::()).await.unwrap();
| -------------------------------------------------------------------------------^^^^^
| | ||
| | |Serve<TapIo<TcpListener, {closure@main.rs:18:17}>, IntoMakeServiceWithConnectInfo<..., ...>, ...> is not a future
| | help: remove the .await
| this call returns Serve<TapIo<tokio::net::TcpListener, {closure@src/main.rs:18:17: 18:29}>, IntoMakeServiceWithConnectInfo<Router, std::net::SocketAddr>, AddExtension<Router, ConnectInfo<std::net::SocketAddr>>>

@ttys3 ttys3 changed the title into_make_service_with_connect_info not work anymore into_make_service_with_connect_info not compile anymore Dec 1, 2024
@jplatte
Copy link
Member

jplatte commented Dec 1, 2024

Thanks for the report! I will look into it soon.

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

Successfully merging a pull request may close this issue.

2 participants