10000 Fix TLS close initiated by Sozu by Wonshtrum · Pull Request #1160 · sozu-proxy/sozu · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix TLS close initiated by Sozu #1160

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

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ impl ProxySession for HttpSession {
}

self.state.cancel_timeouts();
// defer backend closing to the state
self.state.close(self.proxy.clone(), &mut self.metrics);

let front_socket = self.state.front_socket();
if let Err(e) = front_socket.shutdown(Shutdown::Both) {
Expand All @@ -328,8 +330,6 @@ impl ProxySession for HttpSession {
}
proxy.remove_session(self.frontend_token);

// defer backend closing to the state
self.state.close(self.proxy.clone(), &mut self.metrics);
self.has_been_closed = true;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ impl ProxySession for HttpsSession {
}

self.state.cancel_timeouts();
// defer backend closing to the state
// in case of https it should also send a close notify on the client before the socket is closed below
self.state.close(self.proxy.clone(), &mut self.metrics);

let front_socket = self.state.front_socket();
if let Err(e) = front_socket.shutdown(Shutdown::Both) {
Expand All @@ -458,8 +461,6 @@ impl ProxySession for HttpsSession {
}
proxy.remove_session(self.frontend_token);

// defer backend closing to the state
self.state.close(self.proxy.clone(), &mut self.metrics);
self.has_been_closed = true;
}

Expand Down
18 changes: 8 additions & 10 deletions lib/src/protocol/kawa_h 8000 1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
let bufs = response_stream.as_io_slice();
if bufs.is_empty() && !self.frontend_socket.socket_wants_write() {
self.frontend_readiness.interest.remove(Ready::WRITABLE);
return StateResult::Continue;
// do not shortcut, response might have been terminated without anything more to send
}

let (size, socket_state) = self.frontend_socket.socket_write_vectored(&bufs);
Expand Down Expand Up @@ -532,6 +532,7 @@
if response_stream.is_terminated() && response_stream.is_completed() {
if self.context.closing {
debug!("{} closing proxy, no keep alive", log_context!(self));
self.log_request_success(metrics);
return StateResult::CloseSession;
}

Expand Down Expand Up @@ -1590,7 +1591,7 @@
}
}

pub fn backend_hup(&mut self, metrics: &mut SessionMetrics) -> StateResult {

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Build documentation

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Build documentation

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (nightly, true)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, stable)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Build Sozu 🦀

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unused variable: `metrics`

Check warning on line 1594 in lib/src/protocol/kawa_h1/mod.rs

View workflow job for this annotation

GitHub Actions / Test (false, beta)

unused variable: `metrics`
let response_stream = match &mut self.response_stream {
ResponseStream::BackendAnswer(response_stream) => response_stream,
_ => return StateResult::CloseBackend,
Expand Down Expand Up @@ -1623,15 +1624,10 @@

response_stream.parsing_phase = kawa::ParsingPhase::Terminated;

// check if there is anything left to write
if response_stream.is_completed() {
// we have to close the session now, because writable would short-cut
self.log_request_success(metrics);
StateResult::CloseSession
} else {
// writable() will be called again and finish the session properly
StateResult::CloseBackend
}
// writable() will be called again and finish the session properly
// for this reason, writable must not short cut
self.frontend_readiness.interest.insert(Ready::WRITABLE);
StateResult::Continue
}
// probably backend hup between keep alive request, change backend
(true, true) => {
Expand Down Expand Up @@ -1912,6 +1908,8 @@

fn close(&mut self, proxy: Rc<RefCell<dyn L7Proxy>>, metrics: &mut SessionMetrics) {
self.close_backend(proxy, metrics);
self.frontend_socket.socket_close();
let _ = self.frontend_socket.socket_write_vectored(&[]);

//if the state was initial, the connection was already reset
if !self.request_stream.is_initial() {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub trait SocketHandler {
fn socket_wants_write(&self) -> bool {
false
}
fn socket_close(&mut self) {}
fn socket_ref(&self) -> &TcpStream;
fn socket_mut(&mut self) -> &mut TcpStream;
fn protocol(&self) -> TransportProtocol;
Expand Down Expand Up @@ -430,6 +431,10 @@ impl SocketHandler for FrontRustls {
}
}

fn socket_close(&mut self) {
self.session.send_close_notify();
}

fn socket_wants_write(&self) -> bool {
self.session.wants_write()
}
Expand Down
Loading
0