nghttpx: Don't keep backend connection if request buffer is not empty

This commit is contained in:
Tatsuhiro Tsujikawa 2016-05-14 17:16:50 +09:00
parent 5ff6da11b1
commit 8026bdd45a
2 changed files with 8 additions and 6 deletions

View File

@ -905,9 +905,12 @@ BlockedLink *Downstream::detach_blocked_link() {
} }
bool Downstream::can_detach_downstream_connection() const { bool Downstream::can_detach_downstream_connection() const {
// We should check request and response buffer. If request buffer
// is not empty, then we might leave downstream connection in weird
// state, especially for HTTP/1.1
return dconn_ && response_state_ == Downstream::MSG_COMPLETE && return dconn_ && response_state_ == Downstream::MSG_COMPLETE &&
request_state_ == Downstream::MSG_COMPLETE && !upgraded_ && request_state_ == Downstream::MSG_COMPLETE && !upgraded_ &&
!resp_.connection_close; !resp_.connection_close && request_buf_.rleft() == 0;
} }
DefaultMemchunks Downstream::pop_response_buf() { DefaultMemchunks Downstream::pop_response_buf() {

View File

@ -628,14 +628,13 @@ int HttpsUpstream::on_write() {
// We need to postpone detachment until all data are sent so that // We need to postpone detachment until all data are sent so that
// we can notify nghttp2 library all data consumed. // we can notify nghttp2 library all data consumed.
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) { if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
if (resp.connection_close || if (downstream->can_detach_downstream_connection()) {
downstream->get_request_state() != Downstream::MSG_COMPLETE) { // Keep-alive
downstream->detach_downstream_connection();
} else {
// Connection close // Connection close
downstream->pop_downstream_connection(); downstream->pop_downstream_connection();
// dconn was deleted // dconn was deleted
} else {
// Keep-alive
downstream->detach_downstream_connection();
} }
// We need this if response ends before request. // We need this if response ends before request.
if (downstream->get_request_state() == Downstream::MSG_COMPLETE) { if (downstream->get_request_state() == Downstream::MSG_COMPLETE) {