diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index a8a43f4a..bf3b8cd9 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -204,6 +204,20 @@ ssize_t http2_data_read_callback(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } if(nread == 0) { + // This is important because it will handle flow control + // stuff. + if(downstream->get_upstream()->resume_read(SHRPX_NO_BUFFER, + downstream) != 0) { + // In this case, downstream may be deleted. + return NGHTTP2_ERR_CALLBACK_FAILURE; + } + + // Check dconn is still alive because Upstream::resume_read() + // may delete downstream which will delete dconn. + if(sd->dconn == nullptr) { + return NGHTTP2_ERR_DEFERRED; + } + if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { if(!downstream->get_upgrade_request() || (downstream->get_response_state() == Downstream::HEADER_COMPLETE && @@ -216,18 +230,6 @@ ssize_t http2_data_read_callback(nghttp2_session *session, } break; } else { - // This is important because it will handle flow control - // stuff. - if(downstream->get_upstream()->resume_read(SHRPX_NO_BUFFER, - downstream) != 0) { - // In this case, downstream may be deleted. - return NGHTTP2_ERR_CALLBACK_FAILURE; - } - // Check dconn is still alive because Upstream::resume_read() - // may delete downstream which will delete dconn. - if(sd->dconn == nullptr) { - return NGHTTP2_ERR_DEFERRED; - } if(evbuffer_get_length(body) == 0) { // Check get_request_state() == MSG_COMPLETE just in case if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index de21af55..4e22cdd8 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -1101,12 +1101,14 @@ ssize_t downstream_data_read_callback(nghttp2_session *session, downstream->disable_upstream_wtimer(); } - if(nread == 0 && ((*data_flags) & NGHTTP2_DATA_FLAG_EOF) == 0) { + if(nread == 0) { if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; } - return NGHTTP2_ERR_DEFERRED; + if(((*data_flags) & NGHTTP2_DATA_FLAG_EOF) == 0) { + return NGHTTP2_ERR_DEFERRED; + } } return nread; } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index fd8515e7..6175c777 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -834,12 +834,14 @@ ssize_t spdy_data_read_callback(spdylay_session *session, downstream->disable_upstream_wtimer(); } - if(nread == 0 && *eof != 1) { + if(nread == 0) { if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) { return SPDYLAY_ERR_CALLBACK_FAILURE; } - return SPDYLAY_ERR_DEFERRED; + if(*eof != 1) { + return SPDYLAY_ERR_DEFERRED; + } } return nread;