Skip to content

Commit beba525

Browse files
Stream: fixed CPU hog when js_filter is registered in both directions.
Previously, a single busy chain was used to track filtered data in both directions. This might lead to a situation when busy chunks are not freed properly and pile up. The fix is to separate busy chain for upstream and downstream directions. This closes #413 issue on Github.
1 parent d24a11a commit beba525

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

nginx/ngx_stream_js_module.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ typedef struct {
4949
ngx_buf_t *buf;
5050
ngx_chain_t **last_out;
5151
ngx_chain_t *free;
52-
ngx_chain_t *busy;
52+
ngx_chain_t *upstream_busy;
53+
ngx_chain_t *downstream_busy;
5354
ngx_int_t status;
5455
#define NGX_JS_EVENT_UPLOAD 0
5556
#define NGX_JS_EVENT_DOWNLOAD 1
@@ -528,7 +529,7 @@ ngx_stream_js_body_filter(ngx_stream_session_t *s, ngx_chain_t *in,
528529
njs_str_t exception;
529530
njs_int_t ret;
530531
ngx_int_t rc;
531-
ngx_chain_t *out, *cl;
532+
ngx_chain_t *out, *cl, **busy;
532533
ngx_connection_t *c, *dst;
533534
ngx_stream_js_ev_t *event;
534535
ngx_stream_js_ctx_t *ctx;
@@ -606,15 +607,17 @@ ngx_stream_js_body_filter(ngx_stream_session_t *s, ngx_chain_t *in,
606607

607608
if (from_upstream) {
608609
dst = c;
610+
busy = &ctx->downstream_busy;
609611

610612
} else {
611613
dst = s->upstream ? s->upstream->peer.connection : NULL;
614+
busy = &ctx->upstream_busy;
612615
}
613616

614617
if (out != NULL || dst == NULL || dst->buffered) {
615618
rc = ngx_stream_next_filter(s, out, from_upstream);
616619

617-
ngx_chain_update_chains(c->pool, &ctx->free, &ctx->busy, &out,
620+
ngx_chain_update_chains(c->pool, &ctx->free, busy, &out,
618621
(ngx_buf_tag_t) &ngx_stream_js_module);
619622

620623
} else {

0 commit comments

Comments
 (0)