Skip to content

Commit

Permalink
handle session close in ProxySession::timeout()
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal authored and FlorentinDUBOIS committed Jul 13, 2022
1 parent 6c2da60 commit c573f40
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
8 changes: 6 additions & 2 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@ impl ProxySession for Session {
.try_remove(self.frontend_token.0);
}

fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
fn timeout(&mut self, token: Token) {
let res = match *unwrap_msg!(self.protocol.as_mut()) {
State::Expect(_) => {
if token == self.frontend_token {
self.front_timeout.triggered();
Expand All @@ -1200,6 +1200,10 @@ impl ProxySession for Session {
}
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
State::WebSocket(ref mut pipe) => pipe.timeout(token, &mut self.metrics),
};

if res == SessionResult::CloseSession {
self.close();
}
}

Expand Down
8 changes: 6 additions & 2 deletions lib/src/https_openssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,8 +1318,8 @@ impl ProxySession for Session {
}
}

fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
fn timeout(&mut self, token: Token) {
let res = match *unwrap_msg!(self.protocol.as_mut()) {
State::Expect(_, _) => {
if token == self.frontend_token {
self.front_timeout.triggered();
Expand All @@ -1338,6 +1338,10 @@ impl ProxySession for Session {
//FIXME: not implemented yet
State::Http2(_) => SessionResult::CloseSession,
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
};

if res == SessionResult::CloseSession {
self.close();
}
}

Expand Down
8 changes: 6 additions & 2 deletions lib/src/https_rustls/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,8 @@ impl ProxySession for Session {
}
}

fn timeout(&mut self, token: Token) -> SessionResult {
match *unwrap_msg!(self.protocol.as_mut()) {
fn timeout(&mut self, token: Token) {
let res = match *unwrap_msg!(self.protocol.as_mut()) {
State::Http(ref mut http) => http.timeout(token, &mut self.metrics),
State::WebSocket(ref mut pipe) => pipe.timeout(token, &mut self.metrics),
_ => {
Expand All @@ -1248,6 +1248,10 @@ impl ProxySession for Session {

SessionResult::CloseSession
}
};

if res == SessionResult::CloseSession {
self.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ pub trait ProxySession {
fn close(&mut self);
/// if a timeout associated with the session triggers, the event loop will
/// call this method with the timeout's token
fn timeout(&mut self, t: Token) -> SessionResult;
fn timeout(&mut self, t: Token);
/// last time the session got an event
fn last_event(&self) -> Instant;
/// displays the session's internal state (for debugging purpose)
Expand Down
6 changes: 2 additions & 4 deletions lib/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,10 +1720,9 @@ impl Server {

let session_token = token.0;
if self.sessions.borrow().slab.contains(session_token) {
let order = self.sessions.borrow_mut().slab[session_token]
self.sessions.borrow_mut().slab[session_token]
.borrow_mut()
.timeout(token);
self.interpret_session_order(SessionToken(session_token), order);
}
}

Expand Down Expand Up @@ -1783,12 +1782,11 @@ impl ProxySession for ListenSession {

fn close(&mut self) {}

fn timeout(&mut self, _token: Token) -> SessionResult {
fn timeout(&mut self, _token: Token) {
error!(
"called ProxySession::timeout(token={:?}, time) on ListenSession {{ protocol: {:?} }}",
_token, self.protocol
);
SessionResult::CloseSession
}
}

Expand Down
6 changes: 2 additions & 4 deletions lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,21 +919,19 @@ impl ProxySession for Session {
}
}

fn timeout(&mut self, token: Token) -> SessionResult {
fn timeout(&mut self, token: Token) {
if self.frontend_token == token {
let dur = Instant::now() - self.last_event;
let front_timeout = self.front_timeout.duration();
if dur < front_timeout {
TIMER.with(|timer| {
timer.borrow_mut().set_timeout(front_timeout - dur, token);
});
SessionResult::Continue
} else {
SessionResult::CloseSession
self.close();
}
} else {
// invalid token, obsolete timeout triggered
SessionResult::Continue
}
}

Expand Down

0 comments on commit c573f40

Please sign in to comment.