Skip to content

Commit

Permalink
Http refactor: move backend logic from Session to State
Browse files Browse the repository at this point in the history
In order to fit HTTP2 modifications later: Mux sessions, generic HTTP

Traits:
  trait L7ListenerHandler (impl by listeners)
  proxy trait L7Proxy (impl by proxies)
  state trait SessionState (impl by Http, Pipe, Expect)

state machines of HTTP, HTTPS and TCP sessions:
  handle backend connection, passthrough, closing
  integrate https logic into new http state
  Replace State::Invalid by State::FailedUpgrade(marker)
  add the Invalid variant to Http state, extract it from the Option
  StateMachineBuilder macro to merge all State related boilerplate
  default behavior for SessionState::shutting_down()
  pass container_frontend_timeout to the State instead of the Session

Session:
  clean closing of all sessions (add has_been_closed field)
  rewrite all session upgrades
  remove unused SessionResult::ReconnectBackend,
  remove HttpSession::back_token() and HttpsSession::back_token()
  make ProxySession::print_session() call SessionState::print_state()
  remove listener token and request timeout from HTTP and HTTPS Session
  Narrowing scopes: StateResult > SessionResult > SessionIsToBeClosed
  replace ProxySession::tokens() with ProxySession::frontend_token()

Server rewrite:
  only the server calls ProxySession::close()
  generic session shutdown for the zombie_check and shutdown()
  change ProxySession::tokens() to frontend_tokens(), fix the zombie checker
  shut_down_sessions_by_frontend_tokens()
  the zombie checker has to be repaired to use only the frontend token

end-to-end tests:
  test_http_behaviors replaces /lib/tests/http.rs
  test_tls_endpoint
  remove try_issue_810_panic_variant, no longer relevant
  Init logger with loglevel error is RUST_LOG is not found
  Use localhost instead of lolcatho.st for e2e test in pipeline

renaming:
  config::HttpListener   -> HttpListenerconfig (same for TCP and HTTPS)
  Session/Listener/Proxy -> add Tcp/Http/Https prefixes
  process_events         -> update_readiness
  ProxySession::print_state -> ProxySession::print_session

Fixed gauges:
  all "protocol.*" gauges are modified by the Sessions only
 "*.active_requests" are explicit

Code cleanliness:
  sort alphabetically the field structs and function arguments relevant to this commit
  Replace if lets with exhaustive pattern matching
  documenting comments in relevant places

Co-authored-by: Emmanuel Bosquet <bjokac@gmail.com>
  • Loading branch information
Wonshtrum and Keksoj committed Feb 13, 2023
1 parent 42350e5 commit 476e230
Show file tree
Hide file tree
Showing 42 changed files with 4,729 additions and 4,868 deletions.
219 changes: 219 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 32 additions & 8 deletions bin/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,25 @@ pub enum HttpListenerCmd {
expect_proxy: bool,
#[clap(long = "sticky-name", help = "sticky session cookie name")]
sticky_name: Option<String>,
#[clap(long = "front-timeout", help = "Set front timeout")]
#[clap(
long = "front-timeout",
help = "maximum time of inactivity for a frontend socket"
)]
front_timeout: Option<u32>,
#[clap(long = "back-timeout", help = "Set back timeout")]
#[clap(
long = "back-timeout",
help = "maximum time of inactivity for a backend socket"
)]
back_timeout: Option<u32>,
#[clap(long = "request-timeout", help = "Set request timeout")]
#[clap(
long = "request-timeout",
help = "maximum time to receive a request since the connection started"
)]
request_timeout: Option<u32>,
#[clap(long = "connect-timeout", help = "Set connect timeout")]
#[clap(
long = "connect-timeout",
help = "maximum time to connect to a backend server"
)]
connect_timeout: Option<u32>,
},
#[clap(name = "remove")]
Expand Down Expand Up @@ -669,13 +681,25 @@ pub enum HttpsListenerCmd {
expect_proxy: bool,
#[clap(long = "sticky-name", help = "sticky session cookie name")]
sticky_name: Option<String>,
#[clap(long = "front-timeout", help = "Set front timeout")]
#[clap(
long = "front-timeout",
help = "maximum time of inactivity for a frontend socket"
)]
front_timeout: Option<u32>,
#[clap(long = "back-timeout", help = "Set back timeout")]
#[clap(
long = "back-timeout",
help = "maximum time of inactivity for a frontend socket"
)]
back_timeout: Option<u32>,
#[clap(long = "request-timeout", help = "Set request timeout")]
#[clap(
long = "request-timeout",
help = "maximum time to receive a request since the connection started"
)]
request_timeout: Option<u32>,
#[clap(long = "connect-timeout", help = "Set connect timeout")]
#[clap(
long = "connect-timeout",
help = "maximum time to connect to a backend server"
)]
connect_timeout: Option<u32>,
},
#[clap(name = "remove")]
Expand Down

0 comments on commit 476e230

Please sign in to comment.