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

do more clean shutdown #506

Merged
merged 2 commits into from
Jan 19, 2025
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
7 changes: 4 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ jobs:
runs-on: ubuntu-24.04
services:
ftp-server:
image: ghcr.io/garethflowers/ftp-server:edge
image: bogem/ftp:latest
env:
FTP_USER: ftpuser
FTP_PASS: ftppass
PASV_ADDRESS: 127.0.0.1
ports:
- '20-21:20-21/tcp'
- '40000-40009:40000-40009/tcp'
- '47400-47470:47400-47470/tcp'
volumes:
- /tmp/ftp:/home/user
- /tmp/vsftpd:/home/vsftpd
httpbin:
image: ghcr.io/psf/httpbin:0.10.2
ports:
Expand Down
13 changes: 10 additions & 3 deletions g3proxy/src/inspect/http/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::sync::Arc;
use async_recursion::async_recursion;
use http::{Method, Version};
use slog::slog_info;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};

use g3_dpi::Protocol;
use g3_io_ext::{FlexBufReader, LimitedBufReadExt};
Expand Down Expand Up @@ -150,7 +150,11 @@ where

r = req_acceptor.accept() => match r {
Some(r) => r,
None => return Ok(None),
None => {
let _ = rsp_io.ups_w.shutdown().await;
let _ = rsp_io.clt_w.shutdown().await;
return Ok(None);
}
},
r = rsp_io.ups_r.fill_wait_data() => {
req_acceptor.close();
Expand All @@ -164,7 +168,10 @@ where

self.req_id += 1;
match r {
HttpRecvRequest::ClientConnectionClosed => return Ok(None),
HttpRecvRequest::ClientConnectionClosed => {
let _ = rsp_io.ups_w.shutdown().await;
return Ok(None);
}
HttpRecvRequest::ClientConnectionError(e) => return Err(e),
HttpRecvRequest::ClientRequestError(e) => {
if let Some(rsp) =
Expand Down
4 changes: 4 additions & 0 deletions g3proxy/src/inspect/imap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,14 @@ where
CloseReason::Client => {
self.handle_client_logout(&mut clt_w, &mut ups_r, &mut relay_buf.rsp_recv_buf)
.await?;
let _ = ups_w.shutdown().await;
let _ = clt_w.shutdown().await;
Ok(())
}
CloseReason::Server => {
self.mark_close_by_server();
let _ = ups_w.shutdown().await;
let _ = clt_w.shutdown().await;
Ok(())
}
CloseReason::Local(e) => {
Expand Down
8 changes: 7 additions & 1 deletion g3proxy/src/inspect/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ where
)
.await?;
match next_action {
ForwardNextAction::Quit => return Ok(None),
ForwardNextAction::Quit => {
let _ = ups_w.shutdown().await;
let _ = clt_w.shutdown().await;
return Ok(None);
}
ForwardNextAction::StartTls => {
return if let Some(tls_interception) = self.ctx.tls_interception() {
let mut start_tls_obj =
Expand Down Expand Up @@ -393,6 +397,8 @@ where
)
.await?;
if transaction.quit() {
let _ = ups_w.shutdown().await;
let _ = clt_w.shutdown().await;
return Ok(None);
}
}
Expand Down
4 changes: 0 additions & 4 deletions g3proxy/src/module/http_forward/connection/eof_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,12 @@ impl HttpConnectionEofCheck {
_ = conn.1.fill_wait_data() => {
// close early when EOF or unexpected data, to avoid waiting at other side
wait_channel.close();
// make sure we correctly shutdown tls connection
// FIXME use async drop at escaper side when supported
let _ = conn.0.shutdown().await;
}
v = &mut wait_channel => {
if matches!(v, Ok(true)) {
let _ = send_channel.send(conn);
} else {
// make sure we correctly shutdown tls connection
// FIXME use async drop at escaper side when supported
let _ = conn.0.shutdown().await;
}
}
Expand Down
Loading