From ccbaaa1e1486773d907f95167bf27f8a0d7e80f9 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 3 Oct 2015 19:00:16 +0900 Subject: [PATCH] nghttpx: Fix freeze in large transfer --- src/shrpx_http2_upstream.cc | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 82858fab..29f6ddf1 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -679,19 +679,18 @@ int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, // Http2Upstream::remove_downstream(). upstream->set_pending_data_downstream(downstream, length - nwrite); } - if (wb->rleft() == 0) { downstream->disable_upstream_wtimer(); } else { downstream->reset_upstream_wtimer(); } - if (length > 0 && downstream->resume_read(SHRPX_NO_BUFFER, length) != 0) { + if (nwrite > 0 && downstream->resume_read(SHRPX_NO_BUFFER, nwrite) != 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; } - if (length > 0) { - downstream->add_response_sent_bodylen(length); + if (nwrite > 0) { + downstream->add_response_sent_bodylen(nwrite); } return nwrite < length ? NGHTTP2_ERR_PAUSE : 0; @@ -938,16 +937,28 @@ int Http2Upstream::on_write() { data_pending_ = nullptr; } else { - auto n = std::min(wb_.wleft(), data_pendinglen_); + auto nwrite = std::min(wb_.wleft(), data_pendinglen_); DefaultMemchunks *body; if (pending_data_downstream_) { body = pending_data_downstream_->get_response_buf(); } else { body = &pending_response_buf_; } - body->remove(wb_.last, n); - wb_.write(n); - data_pendinglen_ -= n; + body->remove(wb_.last, nwrite); + wb_.write(nwrite); + data_pendinglen_ -= nwrite; + + if (pending_data_downstream_) { + if (nwrite > 0 && + pending_data_downstream_->resume_read(SHRPX_NO_BUFFER, nwrite) != + 0) { + return -1; + } + + if (nwrite > 0) { + pending_data_downstream_->add_response_sent_bodylen(nwrite); + } + } if (data_pendinglen_ > 0) { return 0;