Skip to content

Commit

Permalink
refactor: enhance helper management and improve graceful shutdown han…
Browse files Browse the repository at this point in the history
…dling
  • Loading branch information
Xerxes-2 committed Nov 23, 2024
1 parent f426ddb commit 06313d2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,26 @@ where
.context("Failed to parse proxy address")?;
let modder = modder.map(Arc::new);

let tx = if settings.helper_on() {
let (tx, helper) = if settings.helper_on() {
let (tx, rx) = channel(32);
// start helper worker
info!("Helper worker started");
tokio::spawn(helper_worker(rx, settings));
Some(tx)
let helper_handle = tokio::spawn(helper_worker(rx, settings));
(Some(tx), Some(helper_handle))
} else {
None
(None, None)
};
let proxy = Proxy::builder()
.with_addr(proxy_addr)
.with_ca(ca)
.with_rustls_client(rustls::crypto::aws_lc_rs::default_provider())
.with_websocket_handler(Handler::new(tx, modder, settings))
.with_graceful_shutdown(graceful_shutdown)
.with_graceful_shutdown(async {
graceful_shutdown.await;
if let Some(helper) = helper {
helper.abort();
}
})
.build()
.context("Failed to build proxy")?;

Expand Down

0 comments on commit 06313d2

Please sign in to comment.