Skip to content

Commit

Permalink
nghttpx: Gracefully shutdown HTTP/3 connection
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Feb 24, 2023
1 parent b400bb5 commit 9526e2f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/shrpx_http3_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ int Http3Upstream::on_write() {
return -1;
}

if (httpconn_ && nghttp3_conn_is_drained(httpconn_)) {
return -1;
}

reset_timer();

return 0;
Expand Down Expand Up @@ -1498,6 +1502,11 @@ void Http3Upstream::on_handler_delete() {
ngtcp2_connection_close_error ccerr;
ngtcp2_connection_close_error_default(&ccerr);

if (worker->get_graceful_shutdown() &&
!ngtcp2_conn_get_handshake_completed(conn_)) {
ccerr.error_code = NGTCP2_CONNECTION_REFUSED;
}

auto nwrite = ngtcp2_conn_write_connection_close(
conn_, &ps.path, &pi, conn_close_.data(), conn_close_.size(), &ccerr,
quic_timestamp());
Expand Down Expand Up @@ -1759,6 +1768,13 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr,
auto worker = handler_->get_worker();
auto quic_conn_handler = worker->get_quic_connection_handler();

if (worker->get_graceful_shutdown()) {
ngtcp2_connection_close_error_set_transport_error(
&last_error_, NGTCP2_CONNECTION_REFUSED, nullptr, 0);

return handle_error();
}

ngtcp2_version_cid vc;

rv =
Expand All @@ -1767,19 +1783,6 @@ int Http3Upstream::on_read(const UpstreamAddr *faddr,
return -1;
}

if (worker->get_graceful_shutdown()) {
ngtcp2_cid ini_dcid, ini_scid;

ngtcp2_cid_init(&ini_dcid, vc.dcid, vc.dcidlen);
ngtcp2_cid_init(&ini_scid, vc.scid, vc.scidlen);

quic_conn_handler->send_connection_close(
faddr, vc.version, ini_dcid, ini_scid, remote_addr, local_addr,
NGTCP2_CONNECTION_REFUSED, datalen * 3);

return -1;
}

retry_close_ = true;

quic_conn_handler->send_retry(handler_->get_upstream_addr(), vc.version,
Expand Down Expand Up @@ -2783,6 +2786,10 @@ int Http3Upstream::start_graceful_shutdown() {
return 0;
}

if (!httpconn_) {
return -1;
}

rv = nghttp3_conn_submit_shutdown_notice(httpconn_);
if (rv != 0) {
ULOG(FATAL, this) << "nghttp3_conn_submit_shutdown_notice: "
Expand Down

0 comments on commit 9526e2f

Please sign in to comment.