diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index 7bb14c5b..a5931231 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -54,6 +54,11 @@ void upstream_writecb(bufferevent *bev, void *arg) { ClientHandler *handler = reinterpret_cast(arg); // We actually depend on write low-warter mark == 0. + if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) { + // Possibly because of deferred callback, we may get this callback + // when the output buffer is not empty. + return; + } if(handler->get_should_close_after_write()) { delete handler; } else { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 2ff6bbe2..776c6c2a 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -417,6 +417,9 @@ void https_downstream_readcb(bufferevent *bev, void *ptr) namespace { void https_downstream_writecb(bufferevent *bev, void *ptr) { + if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) { + return; + } DownstreamConnection *dconn = reinterpret_cast(ptr); Downstream *downstream = dconn->get_downstream(); HttpsUpstream *upstream; diff --git a/src/shrpx_spdy_session.cc b/src/shrpx_spdy_session.cc index ba4693db..7694a45a 100644 --- a/src/shrpx_spdy_session.cc +++ b/src/shrpx_spdy_session.cc @@ -194,6 +194,9 @@ void readcb(bufferevent *bev, void *ptr) namespace { void writecb(bufferevent *bev, void *ptr) { + if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) { + return; + } int rv; SpdySession *spdy = reinterpret_cast(ptr); rv = spdy->on_write(); diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 19196703..b3719032 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -491,6 +491,9 @@ void spdy_downstream_readcb(bufferevent *bev, void *ptr) namespace { void spdy_downstream_writecb(bufferevent *bev, void *ptr) { + if(evbuffer_get_length(bufferevent_get_output(bev)) > 0) { + return; + } DownstreamConnection *dconn = reinterpret_cast(ptr); Downstream *downstream = dconn->get_downstream(); SpdyUpstream *upstream;