Skip to content

Commit

Permalink
nghttpx: Fix backend stall if header and request body are sent in 2 p…
Browse files Browse the repository at this point in the history
…ackets
  • Loading branch information
tatsuhiro-t committed Jan 23, 2019
1 parent 8dc2b26 commit d93842d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/shrpx_downstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ int Downstream::push_request_headers() {
int Downstream::push_upload_data_chunk(const uint8_t *data, size_t datalen) {
req_.recv_body_length += datalen;

if (!request_header_sent_) {
if (!dconn_ && !request_header_sent_) {
blocked_request_buf_.append(data, datalen);
req_.unconsumed_body_length += datalen;
return 0;
Expand All @@ -662,7 +662,7 @@ int Downstream::push_upload_data_chunk(const uint8_t *data, size_t datalen) {
}

int Downstream::end_upload_data() {
if (!request_header_sent_) {
if (!dconn_ && !request_header_sent_) {
blocked_request_data_eof_ = true;
return 0;
}
Expand Down Expand Up @@ -1141,6 +1141,10 @@ bool Downstream::get_blocked_request_data_eof() const {
return blocked_request_data_eof_;
}

void Downstream::set_blocked_request_data_eof(bool f) {
blocked_request_data_eof_ = f;
}

void Downstream::set_ws_key(const StringRef &key) { ws_key_ = key; }

} // namespace shrpx
1 change: 1 addition & 0 deletions src/shrpx_downstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class Downstream {

DefaultMemchunks *get_blocked_request_buf();
bool get_blocked_request_data_eof() const;
void set_blocked_request_data_eof(bool f);

// downstream response API
const Response &response() const { return resp_; }
Expand Down
13 changes: 13 additions & 0 deletions src/shrpx_http2_downstream_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,14 @@ int Http2DownstreamConnection::push_request_headers() {

int Http2DownstreamConnection::push_upload_data_chunk(const uint8_t *data,
size_t datalen) {
if (!downstream_->get_request_header_sent()) {
auto output = downstream_->get_blocked_request_buf();
auto &req = downstream_->request();
output->append(data, datalen);
req.unconsumed_body_length += datalen;
return 0;
}

int rv;
auto output = downstream_->get_request_buf();
output->append(data, datalen);
Expand All @@ -516,6 +524,11 @@ int Http2DownstreamConnection::push_upload_data_chunk(const uint8_t *data,
}

int Http2DownstreamConnection::end_upload_data() {
if (!downstream_->get_request_header_sent()) {
downstream_->set_blocked_request_data_eof(true);
return 0;
}

int rv;
if (downstream_->get_downstream_stream_id() != -1) {
rv = http2session_->resume_data(this);
Expand Down
19 changes: 19 additions & 0 deletions src/shrpx_http_downstream_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,17 @@ int HttpDownstreamConnection::process_blocked_request_buf() {

int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data,
size_t datalen) {
if (!downstream_->get_request_header_sent()) {
auto output = downstream_->get_blocked_request_buf();
auto &req = downstream_->request();
output->append(data, datalen);
req.unconsumed_body_length += datalen;
if (request_header_written_) {
signal_write();
}
return 0;
}

auto chunked = downstream_->get_chunked_request();
auto output = downstream_->get_request_buf();

Expand All @@ -726,6 +737,14 @@ int HttpDownstreamConnection::push_upload_data_chunk(const uint8_t *data,
}

int HttpDownstreamConnection::end_upload_data() {
if (!downstream_->get_request_header_sent()) {
downstream_->set_blocked_request_data_eof(true);
if (request_header_written_) {
signal_write();
}
return 0;
}

signal_write();

if (!downstream_->get_chunked_request()) {
Expand Down

0 comments on commit d93842d

Please sign in to comment.