nghttpx: Don't connect backend if connection is not establish up front

This commit is contained in:
Tatsuhiro Tsujikawa 2014-12-15 23:34:00 +09:00
parent 403ece66e3
commit 556811ec64
2 changed files with 19 additions and 9 deletions

View File

@ -60,7 +60,7 @@ Http2Session::Http2Session(event_base *evbase, SSL_CTX *ssl_ctx)
Http2Session::~Http2Session() { disconnect(); } Http2Session::~Http2Session() { disconnect(); }
int Http2Session::disconnect() { int Http2Session::disconnect(bool hard) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "Disconnecting"; SSLOG(INFO, this) << "Disconnecting";
} }
@ -140,6 +140,10 @@ int Http2Session::disconnect() {
handlers.insert(dc->get_client_handler()); handlers.insert(dc->get_client_handler());
} }
for (auto h : handlers) { for (auto h : handlers) {
if (hard) {
delete h;
continue;
}
if (h->get_upstream()->on_downstream_reset() != 0) { if (h->get_upstream()->on_downstream_reset() != 0) {
delete h; delete h;
} }
@ -271,13 +275,13 @@ void eventcb(bufferevent *bev, short events, void *ptr) {
if (!get_config()->downstream_no_tls && !get_config()->insecure && if (!get_config()->downstream_no_tls && !get_config()->insecure &&
http2session->check_cert() != 0) { http2session->check_cert() != 0) {
http2session->disconnect(); http2session->disconnect(true);
return; return;
} }
if (http2session->on_connect() != 0) { if (http2session->on_connect() != 0) {
http2session->disconnect(); http2session->disconnect(true);
return; return;
} }
@ -296,7 +300,8 @@ void eventcb(bufferevent *bev, short events, void *ptr) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "EOF"; SSLOG(INFO, http2session) << "EOF";
} }
http2session->disconnect(); http2session->disconnect(http2session->get_state() ==
Http2Session::CONNECTING);
return; return;
} }
@ -308,7 +313,8 @@ void eventcb(bufferevent *bev, short events, void *ptr) {
SSLOG(INFO, http2session) << "Timeout"; SSLOG(INFO, http2session) << "Timeout";
} }
} }
http2session->disconnect(); http2session->disconnect(http2session->get_state() ==
Http2Session::CONNECTING);
return; return;
} }
} }
@ -364,7 +370,7 @@ void proxy_eventcb(bufferevent *bev, short events, void *ptr) {
} }
if (bufferevent_write(bev, req.c_str(), req.size()) != 0) { if (bufferevent_write(bev, req.c_str(), req.size()) != 0) {
SSLOG(ERROR, http2session) << "bufferevent_write() failed"; SSLOG(ERROR, http2session) << "bufferevent_write() failed";
http2session->disconnect(); http2session->disconnect(true);
} }
return; return;
} }
@ -373,7 +379,8 @@ void proxy_eventcb(bufferevent *bev, short events, void *ptr) {
if (LOG_ENABLED(INFO)) { if (LOG_ENABLED(INFO)) {
SSLOG(INFO, http2session) << "Proxy EOF"; SSLOG(INFO, http2session) << "Proxy EOF";
} }
http2session->disconnect(); http2session->disconnect(http2session->get_state() ==
Http2Session::PROXY_CONNECTING);
return; return;
} }
@ -385,7 +392,8 @@ void proxy_eventcb(bufferevent *bev, short events, void *ptr) {
SSLOG(INFO, http2session) << "Timeout"; SSLOG(INFO, http2session) << "Timeout";
} }
} }
http2session->disconnect(); http2session->disconnect(http2session->get_state() ==
Http2Session::PROXY_CONNECTING);
return; return;
} }
} }

View File

@ -56,7 +56,9 @@ public:
int check_cert(); int check_cert();
int disconnect(); // If hard is true, all pending requests are abandoned and
// associated ClientHandlers will be deleted.
int disconnect(bool hard = false);
int initiate_connection(); int initiate_connection();
void add_downstream_connection(Http2DownstreamConnection *dconn); void add_downstream_connection(Http2DownstreamConnection *dconn);