diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 04702200..c8065bb4 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -81,11 +81,9 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) { delete handler; return; } - if (ev_is_active(handler->get_wev())) { - if (handler->do_write() != 0) { - delete handler; - return; - } + if (handler->do_write() != 0) { + delete handler; + return; } } } // namespace diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 95b9e0ea..fc2f9d86 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -114,7 +114,8 @@ HttpDownstreamConnection::HttpDownstreamConnection( conn_(loop, -1, nullptr, get_config()->downstream_write_timeout, get_config()->downstream_read_timeout, 0, 0, 0, 0, connectcb, readcb, timeoutcb, this), - ioctrl_(&conn_.rlimit), response_htp_{0}, addr_idx_(0) {} + ioctrl_(&conn_.rlimit), response_htp_{0}, addr_idx_(0), + connected_(false) {} HttpDownstreamConnection::~HttpDownstreamConnection() { // Downstream and DownstreamConnection may be deleted @@ -670,6 +671,10 @@ http_parser_settings htp_hooks = { } // namespace int HttpDownstreamConnection::on_read() { + if (!connected_) { + return 0; + } + ev_timer_again(conn_.loop, &conn_.rt); std::array buf; int rv; @@ -742,6 +747,10 @@ int HttpDownstreamConnection::on_read() { } int HttpDownstreamConnection::on_write() { + if (!connected_) { + return 0; + } + ev_timer_again(conn_.loop, &conn_.rt); auto upstream = downstream_->get_upstream(); @@ -789,6 +798,8 @@ int HttpDownstreamConnection::on_connect() { return -1; } + connected_ = true; + connect_blocker->on_success(); conn_.rlimit.startw(); diff --git a/src/shrpx_http_downstream_connection.h b/src/shrpx_http_downstream_connection.h index 87354a9e..02480d5b 100644 --- a/src/shrpx_http_downstream_connection.h +++ b/src/shrpx_http_downstream_connection.h @@ -70,6 +70,7 @@ private: http_parser response_htp_; // index of get_config()->downstream_addrs this object is using size_t addr_idx_; + bool connected_; }; } // namespace shrpx