Skip to content

Commit

Permalink
Merge pull request alibaba#527 from chobits/spdy_bugfix
Browse files Browse the repository at this point in the history
SPDY: fix connection leak
  • Loading branch information
yaoweibin committed Oct 17, 2014
2 parents 57216c4 + 2998721 commit 728a397
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/http/ngx_http_spdy.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ static void ngx_http_spdy_handle_connection_handler(ngx_event_t *rev);
static void ngx_http_spdy_keepalive_handler(ngx_event_t *rev);
static void ngx_http_spdy_finalize_connection(ngx_http_spdy_connection_t *sc,
ngx_int_t rc);
static ngx_int_t ngx_http_spdy_pending(ngx_http_spdy_connection_t *sc);

static void ngx_http_spdy_pool_cleanup(void *data);

Expand Down Expand Up @@ -518,7 +519,7 @@ ngx_http_spdy_send_output_queue(ngx_http_spdy_connection_t *sc)
return NGX_ERROR; /* FIXME */
}

if (cl) {
if (cl || ngx_http_spdy_pending(sc)) {
ngx_add_timer(wev, clcf->send_timeout);

} else {
Expand Down Expand Up @@ -558,6 +559,37 @@ ngx_http_spdy_send_output_queue(ngx_http_spdy_connection_t *sc)
}


static ngx_int_t
ngx_http_spdy_pending(ngx_http_spdy_connection_t *sc)
{
ngx_uint_t i, size;
ngx_http_spdy_stream_t *stream;
ngx_http_spdy_srv_conf_t *sscf;

sscf = ngx_http_get_module_srv_conf(sc->http_connection->conf_ctx,
ngx_http_spdy_module);

size = ngx_http_spdy_streams_index_size(sscf);

for (i = 0; i < size; i++) {
stream = sc->streams_index[i];

while (stream) {

if (stream->pending) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, sc->connection->log, 0,
"spdy pending");
return 1;
}

stream = stream->index;
}
}

return 0;
}


static void
ngx_http_spdy_handle_connection(ngx_http_spdy_connection_t *sc)
{
Expand Down
21 changes: 21 additions & 0 deletions src/http/ngx_http_spdy_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ ngx_http_spdy_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_chain_t *cl, *ll, *out, **ln;
ngx_http_spdy_stream_t *stream;
ngx_http_spdy_out_frame_t *frame;
ngx_http_spdy_connection_t *sc;

stream = r->spdy_stream;

Expand All @@ -1205,6 +1206,12 @@ ngx_http_spdy_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"spdy body filter \"%V?%V\"", &r->uri, &r->args);

sc = stream->connection;

if (sc->connection->error || r->connection->error) {
return NGX_ERROR;
}

if (in == NULL || r->header_only) {

if (stream->waiting) {
Expand Down Expand Up @@ -1289,7 +1296,9 @@ ngx_http_spdy_v3_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_chain_t *cl, *tl, *ll, *out, **ln;
ngx_http_spdy_stream_t *stream;
ngx_http_spdy_srv_conf_t *sscf;
ngx_http_core_loc_conf_t *clcf;
ngx_http_spdy_out_frame_t *frame;
ngx_http_spdy_connection_t *sc;

total = 0;
size = 0;
Expand All @@ -1303,6 +1312,12 @@ ngx_http_spdy_v3_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"spdy body filter \"%V?%V\"", &r->uri, &r->args);

sc = stream->connection;

if (sc->connection->error || r->connection->error) {
return NGX_ERROR;
}

if (in == NULL || r->header_only) {

if (stream->pending && (stream->send_window_size > 0)) {
Expand Down Expand Up @@ -1389,6 +1404,12 @@ ngx_http_spdy_v3_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
"zero send windows size");

if (!sc->connection->write->timer_set) {
clcf = ngx_http_get_module_loc_conf(sc->http_connection->conf_ctx,
ngx_http_core_module);
ngx_add_timer(sc->connection->write, clcf->send_timeout);
}

r->connection->buffered |= NGX_SPDY_WRITE_BUFFERED;
return NGX_AGAIN;
} else if (total > stream->send_window_size) {
Expand Down

0 comments on commit 728a397

Please sign in to comment.