nghttpx: Fix freeze in large transfer

This commit is contained in:
Tatsuhiro Tsujikawa 2015-10-03 19:00:16 +09:00
parent 9fa5010eac
commit ccbaaa1e14
1 changed files with 19 additions and 8 deletions

View File

@ -679,19 +679,18 @@ int send_data_callback(nghttp2_session *session, nghttp2_frame *frame,
// Http2Upstream::remove_downstream(). // Http2Upstream::remove_downstream().
upstream->set_pending_data_downstream(downstream, length - nwrite); upstream->set_pending_data_downstream(downstream, length - nwrite);
} }
if (wb->rleft() == 0) { if (wb->rleft() == 0) {
downstream->disable_upstream_wtimer(); downstream->disable_upstream_wtimer();
} else { } else {
downstream->reset_upstream_wtimer(); 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; return NGHTTP2_ERR_CALLBACK_FAILURE;
} }
if (length > 0) { if (nwrite > 0) {
downstream->add_response_sent_bodylen(length); downstream->add_response_sent_bodylen(nwrite);
} }
return nwrite < length ? NGHTTP2_ERR_PAUSE : 0; return nwrite < length ? NGHTTP2_ERR_PAUSE : 0;
@ -938,16 +937,28 @@ int Http2Upstream::on_write() {
data_pending_ = nullptr; data_pending_ = nullptr;
} else { } else {
auto n = std::min(wb_.wleft(), data_pendinglen_); auto nwrite = std::min(wb_.wleft(), data_pendinglen_);
DefaultMemchunks *body; DefaultMemchunks *body;
if (pending_data_downstream_) { if (pending_data_downstream_) {
body = pending_data_downstream_->get_response_buf(); body = pending_data_downstream_->get_response_buf();
} else { } else {
body = &pending_response_buf_; body = &pending_response_buf_;
} }
body->remove(wb_.last, n); body->remove(wb_.last, nwrite);
wb_.write(n); wb_.write(nwrite);
data_pendinglen_ -= n; 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) { if (data_pendinglen_ > 0) {
return 0; return 0;