Drop connection without error on early read termination #2764

This commit is contained in:
Kevin Rauwolf 2022-06-10 16:09:12 -07:00
parent 30004d5b9f
commit a9e89b0db9
1 changed files with 12 additions and 12 deletions

View File

@ -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);
}
}