408 Request timeout after 5 minutes on some servers

104 views Asked by At

I am getting 408 Request Timeout every 5 minutes on some servers. In the trace logs, these servers have the keep_alive status as Disabled.

[2024-01-17T01:59:01Z TRACE hyper::proto::h1::conn] flushed({role=server}): State { reading: Body(Length(37703933)), writing: Init, keep_alive: Disabled }
[2024-01-17T01:59:01Z TRACE hyper::proto::h1::decode] decode; state=Length(37703933)
[2024-01-17T01:59:01Z TRACE hyper::proto::h1::io] received 0 bytes
[2024-01-17T01:59:01Z DEBUG hyper::proto::h1::conn] incoming body decode error: end of file before message length reached

I am using axum to configure my server on the backend as below:

let app = Router::new()
   .route("/api", get(graphiql).post(graphql_handler))
   .route("/api/", get(graphiql).post(graphql_handler))
   .layer(Extension(schema))
   .layer(CorsLayer::permissive())
   .layer(
       ServiceBuilder::new()
           .layer(HandleErrorLayer::new(|_: BoxError| async {
               info!(target: LOG_TARGET, "timeout occured");
               StatusCode::REQUEST_TIMEOUT
           }))
           .layer(TimeoutLayer::new(Duration::from_secs(3600))),
   )
   .layer(TraceLayer::new_for_http());

The timeout is happening when uploading a file and takes more than 5 minutes. The upload is done using the async-graphql Upload feature.

pub struct FileUploadForm {
    pub new_file: Upload,
}
async fn upload_file<'a>(&self, ctx: &Context<'a>, form: FileUploadForm) -> Result<bool> {
    // File handling logic
}

The following is request header:

Request URL: http://domain/api/
Referrer Policy: strict-origin-when-cross-origin
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en
Content-Length: 38878148
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryodalzl0fqvm4RwDW
Proxy-Connection: keep-alive
Sec-Gpc: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

How can I configure the server to keep the connection open?

0

There are 0 answers