From 2010401b81fe90be4a6cd6f62bf47c69259757bc Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 27 Aug 2021 18:19:44 +0900 Subject: [PATCH] nghttpx: Send APPLICATION_CLOSE on app read timeout --- src/shrpx_http3_upstream.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc index 1c1cabce..0287f591 100644 --- a/src/shrpx_http3_upstream.cc +++ b/src/shrpx_http3_upstream.cc @@ -1238,6 +1238,34 @@ void Http3Upstream::on_handler_delete() { handler_->write_accesslog(d); } } + + // If this is not idle close, send APPLICATION_CLOSE since this + // might come before idle close. + if (!ngtcp2_conn_is_in_closing_period(conn_) && + !ngtcp2_conn_is_in_draining_period(conn_)) { + ngtcp2_path_storage ps; + ngtcp2_pkt_info pi; + std::array buf; + + ngtcp2_path_storage_zero(&ps); + + auto nwrite = ngtcp2_conn_write_application_close( + conn_, &ps.path, &pi, buf.data(), buf.size(), NGHTTP3_H3_NO_ERROR, + quic_timestamp()); + if (nwrite < 0) { + if (nwrite != NGTCP2_ERR_INVALID_STATE) { + LOG(ERROR) << "ngtcp2_conn_write_application_close: " + << ngtcp2_strerror(nwrite); + } + + return; + } + + quic_send_packet(static_cast(ps.path.user_data), + ps.path.remote.addr, ps.path.remote.addrlen, + ps.path.local.addr, ps.path.local.addrlen, buf.data(), + nwrite, 0); + } } int Http3Upstream::on_downstream_reset(Downstream *downstream, bool no_retry) {