From 4876412f7d9644d4dc0834f5d439bcaa1a710273 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 9 Feb 2013 17:03:03 +0900 Subject: [PATCH] shrpx: Check return value of HttpsUpstream::resume_read() Currently, resume_read() fails if on_read() returns -1 in case that evbuffer_add failed, which means, most likely, memory allocation failure. ClientHandler is marked "should be closed", but if evbuffer_add is failed, write callback will not be invoked and its marking is not evaluated. It will eventually be deleted when the client is disconnected or backend failure though. --- src/shrpx_https_upstream.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index aea4b99..27e4a52 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -399,7 +399,9 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) } else { upstream->delete_downstream(); // Process next HTTP request - upstream->resume_read(SHRPX_MSG_BLOCK, 0); + if(upstream->resume_read(SHRPX_MSG_BLOCK, 0) == -1) { + return; + } } } } else { @@ -425,7 +427,9 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { upstream->delete_downstream(); // Process next HTTP request - upstream->resume_read(SHRPX_MSG_BLOCK, 0); + if(upstream->resume_read(SHRPX_MSG_BLOCK, 0) == -1) { + return; + } } } } @@ -442,6 +446,7 @@ void https_downstream_writecb(bufferevent *bev, void *ptr) Downstream *downstream = dconn->get_downstream(); HttpsUpstream *upstream; upstream = static_cast(downstream->get_upstream()); + // May return -1 upstream->resume_read(SHRPX_NO_BUFFER, downstream); } } // namespace @@ -493,7 +498,9 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr) } if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { upstream->delete_downstream(); - upstream->resume_read(SHRPX_MSG_BLOCK, 0); + if(upstream->resume_read(SHRPX_MSG_BLOCK, 0) == -1) { + return; + } } } else if(events & (BEV_EVENT_ERROR | BEV_EVENT_TIMEOUT)) { if(LOG_ENABLED(INFO)) { @@ -517,7 +524,9 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr) } if(downstream->get_request_state() == Downstream::MSG_COMPLETE) { upstream->delete_downstream(); - upstream->resume_read(SHRPX_MSG_BLOCK, 0); + if(upstream->resume_read(SHRPX_MSG_BLOCK, 0) == -1) { + return; + } } } }