fix(client): don't reuse a connection while still flushing
A client connection that read a full response while the request body was still flushing would see incorrect behavior, since the pool would let it be checked out again for a new request. In debug builds, it would then panic, but in release builds it would intermix the 2nd request bytes with the body of the previous request. In practice, this only ever happens if a server replies with a full response before reading the full request, while also choosing to not close that connection. Most servers either wait for the full request, or close the connection after the new response is written, so as to stop reading.
This commit is contained in:
@@ -98,13 +98,18 @@ where
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
pub(crate) fn set_write_strategy_flatten(&mut self) {
|
||||
fn set_write_strategy_flatten(&mut self) {
|
||||
// this should always be called only at construction time,
|
||||
// so this assert is here to catch myself
|
||||
debug_assert!(self.write_buf.queue.bufs_cnt() == 0);
|
||||
self.write_buf.set_strategy(WriteStrategy::Flatten);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_write_strategy_queue(&mut self) {
|
||||
self.write_buf.set_strategy(WriteStrategy::Queue);
|
||||
}
|
||||
|
||||
pub(crate) fn read_buf(&self) -> &[u8] {
|
||||
self.read_buf.as_ref()
|
||||
}
|
||||
@@ -121,6 +126,15 @@ where
|
||||
self.read_buf.capacity() - self.read_buf.len()
|
||||
}
|
||||
|
||||
/// Return whether we can append to the headers buffer.
|
||||
///
|
||||
/// Reasons we can't:
|
||||
/// - The write buf is in queue mode, and some of the past body is still
|
||||
/// needing to be flushed.
|
||||
pub(crate) fn can_headers_buf(&self) -> bool {
|
||||
!self.write_buf.queue.has_remaining()
|
||||
}
|
||||
|
||||
pub(crate) fn headers_buf(&mut self) -> &mut Vec<u8> {
|
||||
let buf = self.write_buf.headers_mut();
|
||||
&mut buf.bytes
|
||||
|
||||
Reference in New Issue
Block a user