allow to turn off forced connection timeout
This commit is contained in:
parent
4aef34434a
commit
b2b3b05fcb
9 changed files with 41 additions and 19 deletions
|
|
@ -52,7 +52,7 @@ thiserror = "1.0.56"
|
|||
http = "1.0.0"
|
||||
http-body-util = "0.1.0"
|
||||
hyper = { version = "1.1.0", default-features = false }
|
||||
hyper-util = { version = "0.1.2", features = ["full"] }
|
||||
hyper-util = { version = "0.1.3", features = ["full"] }
|
||||
futures-util = { version = "0.3.30", default-features = false }
|
||||
futures-channel = { version = "0.3.30", default-features = false }
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ hyper-rustls = { version = "0.26.0", default-features = false, features = [
|
|||
], optional = true }
|
||||
|
||||
# tls and cert management for server
|
||||
hot_reload = "0.1.4"
|
||||
hot_reload = "0.1.5"
|
||||
rustls = { version = "0.21.10", default-features = false }
|
||||
tokio-rustls = { version = "0.24.1", features = ["early-data"] }
|
||||
webpki = "0.22.4"
|
||||
|
|
@ -93,11 +93,11 @@ socket2 = { version = "0.5.5", features = ["all"], optional = true }
|
|||
|
||||
# cache
|
||||
http-cache-semantics = { path = "../submodules/rusty-http-cache-semantics/", optional = true }
|
||||
lru = { version = "0.12.1", optional = true }
|
||||
lru = { version = "0.12.2", optional = true }
|
||||
sha2 = { version = "0.10.8", default-features = false, optional = true }
|
||||
|
||||
# cookie handling for sticky cookie
|
||||
chrono = { version = "0.4.32", default-features = false, features = [
|
||||
chrono = { version = "0.4.33", default-features = false, features = [
|
||||
"unstable-locales",
|
||||
"alloc",
|
||||
"clock",
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ pub const MAX_CONCURRENT_STREAMS: u32 = 64;
|
|||
pub const CERTS_WATCH_DELAY_SECS: u32 = 60;
|
||||
pub const LOAD_CERTS_ONLY_WHEN_UPDATED: bool = true;
|
||||
|
||||
pub const CONNECTION_TIMEOUT_SEC: u64 = 60; // timeout to serve a connection, total time of receive request, serve, and send response. this might limits the max length of response.
|
||||
|
||||
// #[cfg(feature = "http3")]
|
||||
// pub const H3_RESPONSE_BUF_SIZE: usize = 65_536; // 64KB
|
||||
// #[cfg(feature = "http3")]
|
||||
|
|
|
|||
|
|
@ -43,7 +43,11 @@ pub struct ProxyConfig {
|
|||
pub keepalive: bool, // when instantiate server
|
||||
|
||||
// experimentals
|
||||
/// SNI consistency check
|
||||
pub sni_consistency: bool, // Handler
|
||||
/// Connection handling timeout
|
||||
/// timeout to handle a connection, total time of receive request, serve, and send response. this might limits the max length of response.
|
||||
pub connection_handling_timeout: Duration,
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
pub cache_enabled: bool,
|
||||
|
|
@ -90,6 +94,7 @@ impl Default for ProxyConfig {
|
|||
keepalive: true,
|
||||
|
||||
sni_consistency: true,
|
||||
connection_handling_timeout: Duration::from_secs(u64::MAX),
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
cache_enabled: false,
|
||||
|
|
|
|||
|
|
@ -55,6 +55,12 @@ where
|
|||
if proxy_config.https_port.is_some() {
|
||||
info!("Listen port: {} (for TLS)", proxy_config.https_port.unwrap());
|
||||
}
|
||||
if proxy_config.connection_handling_timeout.as_secs() < u64::MAX {
|
||||
info!(
|
||||
"Force connection handling timeout: {} sec",
|
||||
proxy_config.connection_handling_timeout.as_secs()
|
||||
);
|
||||
}
|
||||
#[cfg(any(feature = "http3-quinn", feature = "http3-s2n"))]
|
||||
if proxy_config.http3 {
|
||||
info!("Experimental HTTP/3.0 is enabled. Note it is still very unstable.");
|
||||
|
|
@ -64,10 +70,7 @@ where
|
|||
}
|
||||
#[cfg(feature = "cache")]
|
||||
if proxy_config.cache_enabled {
|
||||
info!(
|
||||
"Cache is enabled: cache dir = {:?}",
|
||||
proxy_config.cache_dir.as_ref().unwrap()
|
||||
);
|
||||
info!("Cache is enabled: cache dir = {:?}", proxy_config.cache_dir.as_ref().unwrap());
|
||||
} else {
|
||||
info!("Cache is disabled")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
use super::proxy_main::Proxy;
|
||||
use crate::{
|
||||
constants::CONNECTION_TIMEOUT_SEC,
|
||||
crypto::CryptoSource,
|
||||
error::*,
|
||||
hyper_ext::body::{IncomingLike, RequestBody},
|
||||
|
|
@ -11,7 +10,7 @@ use bytes::{Buf, Bytes};
|
|||
use http::{Request, Response};
|
||||
use http_body_util::BodyExt;
|
||||
use hyper_util::client::legacy::connect::Connect;
|
||||
use std::{net::SocketAddr, time::Duration};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
#[cfg(feature = "http3-quinn")]
|
||||
use h3::{quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream};
|
||||
|
|
@ -72,7 +71,7 @@ where
|
|||
let tls_server_name_inner = tls_server_name.clone();
|
||||
self.globals.runtime_handle.spawn(async move {
|
||||
if let Err(e) = tokio::time::timeout(
|
||||
Duration::from_secs(CONNECTION_TIMEOUT_SEC + 1), // just in case...
|
||||
self_inner.globals.proxy_config.connection_handling_timeout,
|
||||
self_inner.h3_serve_stream(req, stream, client_addr, tls_server_name_inner),
|
||||
)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use super::socket::bind_tcp_socket;
|
||||
use crate::{
|
||||
constants::{CONNECTION_TIMEOUT_SEC, TLS_HANDSHAKE_TIMEOUT_SEC},
|
||||
constants::TLS_HANDSHAKE_TIMEOUT_SEC,
|
||||
crypto::{CryptoSource, ServerCrypto, SniServerCryptoMap},
|
||||
error::*,
|
||||
globals::Globals,
|
||||
|
|
@ -88,9 +88,11 @@ where
|
|||
let message_handler_clone = self.message_handler.clone();
|
||||
let tls_enabled = self.tls_enabled;
|
||||
let listening_on = self.listening_on;
|
||||
let handling_timeout = self.globals.proxy_config.connection_handling_timeout;
|
||||
|
||||
self.globals.runtime_handle.clone().spawn(async move {
|
||||
timeout(
|
||||
Duration::from_secs(CONNECTION_TIMEOUT_SEC) + Duration::from_secs(1), // just in case...
|
||||
handling_timeout,
|
||||
server_clone.serve_connection_with_upgrades(
|
||||
stream,
|
||||
service_fn(move |req: Request<Incoming>| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue