nghttpx: Fix crash with API request

This commit is contained in:
Tatsuhiro Tsujikawa 2018-08-24 23:07:16 +09:00
parent 0422f8a844
commit 32826466f5
3 changed files with 53 additions and 39 deletions

View File

@ -191,8 +191,10 @@ Downstream::~Downstream() {
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
if (dconn_) { if (dconn_) {
const auto &group = dconn_->get_downstream_addr_group(); const auto &group = dconn_->get_downstream_addr_group();
const auto &mruby_ctx = group->mruby_ctx; if (group) {
mruby_ctx->delete_downstream(this); const auto &mruby_ctx = group->mruby_ctx;
mruby_ctx->delete_downstream(this);
}
} }
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
@ -227,8 +229,10 @@ void Downstream::detach_downstream_connection() {
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
const auto &group = dconn_->get_downstream_addr_group(); const auto &group = dconn_->get_downstream_addr_group();
const auto &mruby_ctx = group->mruby_ctx; if (group) {
mruby_ctx->delete_downstream(this); const auto &mruby_ctx = group->mruby_ctx;
mruby_ctx->delete_downstream(this);
}
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
dconn_->detach_downstream(this); dconn_->detach_downstream(this);
@ -250,8 +254,10 @@ std::unique_ptr<DownstreamConnection> Downstream::pop_downstream_connection() {
} }
const auto &group = dconn_->get_downstream_addr_group(); const auto &group = dconn_->get_downstream_addr_group();
const auto &mruby_ctx = group->mruby_ctx; if (group) {
mruby_ctx->delete_downstream(this); const auto &mruby_ctx = group->mruby_ctx;
mruby_ctx->delete_downstream(this);
}
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
return std::unique_ptr<DownstreamConnection>(dconn_.release()); return std::unique_ptr<DownstreamConnection>(dconn_.release());

View File

@ -480,19 +480,21 @@ void Http2Upstream::initiate_downstream(Downstream *downstream) {
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
const auto &group = dconn_ptr->get_downstream_addr_group(); const auto &group = dconn_ptr->get_downstream_addr_group();
const auto &mruby_ctx = group->mruby_ctx; if (group) {
if (mruby_ctx->run_on_request_proc(downstream) != 0) { const auto &mruby_ctx = group->mruby_ctx;
if (error_reply(downstream, 500) != 0) { if (mruby_ctx->run_on_request_proc(downstream) != 0) {
rst_stream(downstream, NGHTTP2_INTERNAL_ERROR); if (error_reply(downstream, 500) != 0) {
rst_stream(downstream, NGHTTP2_INTERNAL_ERROR);
}
downstream_queue_.mark_failure(downstream);
return;
} }
downstream_queue_.mark_failure(downstream); if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return;
return; }
}
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return;
} }
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
@ -1635,18 +1637,20 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) {
if (!downstream->get_non_final_response()) { if (!downstream->get_non_final_response()) {
auto dconn = downstream->get_downstream_connection(); auto dconn = downstream->get_downstream_connection();
const auto &group = dconn->get_downstream_addr_group(); const auto &group = dconn->get_downstream_addr_group();
const auto &dmruby_ctx = group->mruby_ctx; if (group) {
const auto &dmruby_ctx = group->mruby_ctx;
if (dmruby_ctx->run_on_response_proc(downstream) != 0) { if (dmruby_ctx->run_on_response_proc(downstream) != 0) {
if (error_reply(downstream, 500) != 0) { if (error_reply(downstream, 500) != 0) {
return -1;
}
// Returning -1 will signal deletion of dconn.
return -1; return -1;
} }
// Returning -1 will signal deletion of dconn.
return -1;
}
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) { if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return -1; return -1;
}
} }
auto worker = handler_->get_worker(); auto worker = handler_->get_worker();

View File

@ -442,15 +442,17 @@ int htp_hdrs_completecb(http_parser *htp) {
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
const auto &group = dconn_ptr->get_downstream_addr_group(); const auto &group = dconn_ptr->get_downstream_addr_group();
const auto &dmruby_ctx = group->mruby_ctx; if (group) {
const auto &dmruby_ctx = group->mruby_ctx;
if (dmruby_ctx->run_on_request_proc(downstream) != 0) { if (dmruby_ctx->run_on_request_proc(downstream) != 0) {
resp.http_status = 500; resp.http_status = 500;
return -1; return -1;
} }
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) { if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return 0; return 0;
}
} }
#endif // HAVE_MRUBY #endif // HAVE_MRUBY
@ -1050,15 +1052,17 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream) {
#ifdef HAVE_MRUBY #ifdef HAVE_MRUBY
if (!downstream->get_non_final_response()) { if (!downstream->get_non_final_response()) {
const auto &group = dconn->get_downstream_addr_group(); const auto &group = dconn->get_downstream_addr_group();
const auto &dmruby_ctx = group->mruby_ctx; if (group) {
const auto &dmruby_ctx = group->mruby_ctx;
if (dmruby_ctx->run_on_response_proc(downstream) != 0) { if (dmruby_ctx->run_on_response_proc(downstream) != 0) {
error_reply(500); error_reply(500);
return -1; return -1;
} }
if (downstream->get_response_state() == Downstream::MSG_COMPLETE) { if (downstream->get_response_state() == Downstream::MSG_COMPLETE) {
return -1; return -1;
}
} }
auto worker = handler_->get_worker(); auto worker = handler_->get_worker();