]> git.kaiwu.me - njs.git/commitdiff
Stream: fixed processing buffered data in body filter.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 10 Feb 2021 14:03:11 +0000 (14:03 +0000)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 10 Feb 2021 14:03:11 +0000 (14:03 +0000)
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.

nginx/ngx_stream_js_module.c

index b4e338818ba1b982e0058f5ebba2acc5cb8977c5..0b24ea76bb3b10bdc9475b9a3c4249cb6dc1674f 100644 (file)
@@ -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,