From 2b19805ef7a61b6e94be5f662f126632451902b5 Mon Sep 17 00:00:00 2001 From: Eloi DEMOLIS Date: Mon, 25 Nov 2024 19:08:05 +0100 Subject: [PATCH] Fix TLS close initiated by Sozu, solution is not ideal Signed-off-by: Eloi DEMOLIS --- lib/src/http.rs | 4 ++-- lib/src/https.rs | 5 +++-- lib/src/protocol/kawa_h1/mod.rs | 18 ++++++++---------- lib/src/socket.rs | 5 +++++ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/src/http.rs b/lib/src/http.rs index 75032c1d7..2f6e69e39 100644 --- a/lib/src/http.rs +++ b/lib/src/http.rs @@ -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) { @@ -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; } diff --git a/lib/src/https.rs b/lib/src/https.rs index 709809d38..ce03d33bd 100644 --- a/lib/src/https.rs +++ b/lib/src/https.rs @@ -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) { @@ -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; } diff --git a/lib/src/protocol/kawa_h1/mod.rs b/lib/src/protocol/kawa_h1/mod.rs index 1e2c86532..270ca7e7e 100644 --- a/lib/src/protocol/kawa_h1/mod.rs +++ b/lib/src/protocol/kawa_h1/mod.rs @@ -492,7 +492,7 @@ impl Http Http Http { @@ -1912,6 +1908,8 @@ impl SessionState fn close(&mut self, proxy: Rc>, 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() { diff --git a/lib/src/socket.rs b/lib/src/socket.rs index a3227a19d..c3014726f 100644 --- a/lib/src/socket.rs +++ b/lib/src/socket.rs @@ -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; @@ -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() }