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

No Connection: close header in response by hyper server, when client sends it. #2973

Closed
AndreiOrmanji opened this issue Aug 31, 2022 · 1 comment
Labels
C-bug Category: bug. Something is wrong. This is bad!

Comments

@AndreiOrmanji
Copy link

Version
axum = { version = "0.5.15" }
tokio = { version = "1.20", features = ["full"] }

Corresponding to Cargo.toml of axum, hyper = { version = "0.14.14" }

Platform
Windows 10 Enterprise x64 (Os build: 19043.1889)

Description
Corresponding to Teardown section of RFC 7230, when client sends Connection: close header, server must close connection and response should contain that header.
[short summary of the bug]

I tried this code:

use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, World!" }));

    axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}

So I've decided to check it with bare hyper, but result is the same:

use std::convert::Infallible;
use std::net::SocketAddr;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};

async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new("Hello, World".into()))
}

#[tokio::main]
async fn main() {
    // We'll bind to 127.0.0.1:3000
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    // A `Service` is needed for every connection, so this
    // creates one from our `hello_world` function.
    let make_svc = make_service_fn(|_conn| async {
        // service_fn converts our function into a `Service`
        Ok::<_, Infallible>(service_fn(hello_world))
    });

    let server = Server::bind(&addr).serve(make_svc);

    // Run this server for... forever!
    if let Err(e) = server.await {
        eprintln!("server error: {}", e);
    }
}

I expected to see this happen:
Same setup with actix-web = "4.1"

use std::convert::Infallible;
use actix_web::{web, App, HttpResponse, HttpServer};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new().route(
            "/",
            web::get().to(|| async {
                Ok::<_, Infallible>(HttpResponse::Ok().body("Hello, World!"))
            }),
        )
    })
    .bind(("127.0.0.1", 3000))?
    .run()
    .await
}

Screenshot of Actix web
Instead, this happened: [explanation]

image

@AndreiOrmanji AndreiOrmanji added the C-bug Category: bug. Something is wrong. This is bad! label Aug 31, 2022
@seanmonstar
Copy link
Member

This was addressed in #3725.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug. Something is wrong. This is bad!
Projects
None yet
Development

No branches or pull requests

2 participants