From a9e89b0db9413f53b099f6c5fad4fc7a82ed2ab7 Mon Sep 17 00:00:00 2001 From: Kevin Rauwolf Date: Fri, 10 Jun 2022 16:09:12 -0700 Subject: [PATCH] Drop connection without error on early read termination #2764 --- actix-http/src/h1/dispatcher.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 52d46cdb4..e2ab1f3c7 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -22,7 +22,7 @@ use crate::{ config::ServiceConfig, error::{DispatchError, ParseError, PayloadError}, service::HttpFlow, - ConnectionType, Error, Extensions, OnConnectData, Request, Response, StatusCode, + Error, Extensions, OnConnectData, Request, Response, StatusCode, }; use super::{ @@ -727,7 +727,7 @@ where this.state.set(State::None); // break out of payload decode loop - break; + return Ok(true); } // Either whole payload is read and loop is broken or more data @@ -739,18 +739,18 @@ where } } - // not enough info to decide if connection is going to be clean or not + // no bytes in the read buffer, but there are still bytes to be read + // according to the content-length header. The client has stopped + // sending data early. Reset the state, set disconnection flag, + // and stop reading. None => { - error!( - "handler did not read whole payload and dispatcher could not \ - drain read buf; return 500 and close connection" - ); - + debug!("client stopped sending data; disconnecting"); + // reset dispatcher state this.flags.insert(Flags::SHUTDOWN); - let mut res = Response::internal_server_error().drop_body(); - res.head_mut().set_connection_type(ConnectionType::Close); - this.messages.push_back(DispatcherMessage::Error(res)); - *this.error = Some(DispatchError::HandlerDroppedPayload); + let _ = this.payload.take(); + this.state.set(State::None); + + // break out of payload decode loop return Ok(true); } }