From: Dmitry Volyntsev Date: Wed, 10 Feb 2021 14:03:11 +0000 (+0000) Subject: Stream: fixed processing buffered data in body filter. X-Git-Tag: 0.5.1~4 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=38a9486559a78c675bbdcc6435b40f447edd7c2d;p=njs.git Stream: fixed processing buffered data in body filter. Previously, when data was proxied to upstream, it may be partially written and is left in upstream connection buffer. Later, when writing becomes possible again, the body filter is called but it fails to call the next filter in the chain. This resulted in hanging connection. The fix is to take the buffered data in upstream connection into account. This fixes #368 issue on Github. --- diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c index b4e33881..0b24ea76 100644 --- a/nginx/ngx_stream_js_module.c +++ b/nginx/ngx_stream_js_module.c @@ -506,7 +506,7 @@ ngx_stream_js_body_filter(ngx_stream_session_t *s, ngx_chain_t *in, njs_int_t ret; ngx_int_t rc; ngx_chain_t *out, *cl; - ngx_connection_t *c; + ngx_connection_t *c, *dst; ngx_stream_js_ev_t *event; ngx_stream_js_ctx_t *ctx; ngx_stream_js_srv_conf_t *jscf; @@ -580,7 +580,14 @@ ngx_stream_js_body_filter(ngx_stream_session_t *s, ngx_chain_t *in, *ctx->last_out = NULL; - if (out != NULL || c->buffered) { + if (from_upstream) { + dst = c; + + } else { + dst = s->upstream ? s->upstream->peer.connection : NULL; + } + + if (out != NULL || dst == NULL || dst->buffered) { rc = ngx_stream_next_filter(s, out, from_upstream); ngx_chain_update_chains(c->pool, &ctx->free, &ctx->busy, &out,