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

Fix close propagation on close-delimited responses with front keep-alive #1077

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{
rc::{Rc, Weak},
};

use kawa;
use mio::{net::TcpStream, Interest, Token};
use rusty_ulid::Ulid;
use sozu_command::{
Expand Down Expand Up @@ -476,8 +475,6 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
}

if self.response_stream.is_terminated() && self.response_stream.is_completed() {
save_http_status_metric(self.context.status, self.log_context());

self.log_request_success(metrics);
metrics.reset();

Expand Down Expand Up @@ -505,8 +502,10 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
_ => (),
}

let response_length_known = self.response_stream.body_size != kawa::BodySize::Empty;
Wonshtrum marked this conversation as resolved.
Show resolved Hide resolved
let request_length_known = self.request_stream.body_size != kawa::BodySize::Empty;
if !(self.request_stream.is_terminated() && self.request_stream.is_completed())
&& self.request_stream.body_size != kawa::BodySize::Empty
&& request_length_known
{
error!("Response terminated before request, this case is not handled properly yet");
incr!("http.early_response_close");
Expand All @@ -519,20 +518,22 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
// with no keepalive on front but keepalive on backend, we could have
// a pool of connections
trace!(
"============== HANDLE KEEP-ALIVE: {} {}",
"============== HANDLE KEEP-ALIVE: {} {} {}",
self.context.keep_alive_frontend,
self.context.keep_alive_backend
self.context.keep_alive_backend,
response_length_known
);
return match (
self.context.keep_alive_frontend,
self.context.keep_alive_backend,
response_length_known
) {
(true, true) => {
(true, true, true) => {
debug!("{} keep alive front/back", self.log_context());
self.reset();
StateResult::Continue
}
(true, false) => {
(true, false, true) => {
debug!("{} keep alive front", self.log_context());
self.reset();
StateResult::CloseBackend
Expand Down Expand Up @@ -848,6 +849,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
}

pub fn log_request_success(&mut self, metrics: &SessionMetrics) {
save_http_status_metric(self.context.status, self.log_context());
self.log_request(metrics, None);
}
pub fn log_default_answer_success(&mut self, metrics: &SessionMetrics) {
Expand Down Expand Up @@ -1489,10 +1491,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
// check if there is anything left to write
if self.response_stream.is_completed() {
// we have to close the session now, because writable would short-cut
self.log_request_error(
metrics,
"backend hangs up, can not be sure that response is complete",
);
self.log_request_success(metrics);
StateResult::CloseSession
} else {
// writable() will be called again and finish the session properly
Expand Down
Loading