Skip to content

Commit 11b5882

Browse files
eaufavorandrewhavck
authored andcommitted
Retry all h2 connection when encountering graceful shutdown
Before this change, the retry only happens on reused connections. The shutting down could also happen on new connections as well. So this change will retry in both cases.
1 parent 2a08042 commit 11b5882

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.bleep

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
580a96a6280ded91caae0630a5d67d0564369f3f
1+
a29925df89353fce33cd5a78459fc99c707f19ab

pingora-core/src/protocols/http/v2/client.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,19 @@ impl Http2Session {
349349
if self.ping_timedout() {
350350
e.etype = PING_TIMEDOUT;
351351
}
352+
353+
// is_go_away: retry via another connection, this connection is being teardown
354+
// should retry
355+
if self.response_header.is_none() {
356+
if let Some(err) = e.root_cause().downcast_ref::<h2::Error>() {
357+
if err.is_go_away()
358+
&& err.is_remote()
359+
&& err.reason().map_or(false, |r| r == h2::Reason::NO_ERROR)
360+
{
361+
e.retry = true.into();
362+
}
363+
}
364+
}
352365
e
353366
}
354367
}
@@ -367,7 +380,7 @@ pub fn write_body(send_body: &mut SendStream<Bytes>, data: Bytes, end: bool) ->
367380
/* Types of errors during h2 header read
368381
1. peer requests to downgrade to h1, mostly IIS server for NTLM: we will downgrade and retry
369382
2. peer sends invalid h2 frames, usually sending h1 only header: we will downgrade and retry
370-
3. peer sends GO_AWAY(NO_ERROR) on reused conn, usually hit http2_max_requests: we will retry
383+
3. peer sends GO_AWAY(NO_ERROR) connection is being shut down: we will retry
371384
4. peer IO error on reused conn, usually firewall kills old conn: we will retry
372385
5. All other errors will terminate the request
373386
*/
@@ -393,9 +406,8 @@ fn handle_read_header_error(e: h2::Error) -> Box<Error> {
393406
&& e.reason().map_or(false, |r| r == h2::Reason::NO_ERROR)
394407
{
395408
// is_go_away: retry via another connection, this connection is being teardown
396-
// only retry if the connection is reused
397409
let mut err = Error::because(H2Error, "while reading h2 header", e);
398-
err.retry = RetryType::ReusedOnly;
410+
err.retry = true.into();
399411
err
400412
} else if e.is_io() {
401413
// is_io: typical if a previously reused connection silently drops it

0 commit comments

Comments
 (0)