]> git.kaiwu.me - njs.git/commit
QuickJS: mark nginx wrapper references during GC
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 14 Aug 2026 02:23:41 +0000 (19:23 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 14 Aug 2026 23:05:54 +0000 (16:05 -0700)
commit5f5384d8bdd5003739d0ad7a31c78f8c3314ed42
tree1ed80478afafc3f505fc9926b9f59a60f34be5ab
parent72d3150a4d99522c242888a578d61b161a70ad97
QuickJS: mark nginx wrapper references during GC

The HTTP request and stream session wrappers hold JavaScript references
that were invisible to the QuickJS cycle collector.  For example, this
creates a cycle through the native request wrapper:

    function content(r) {
        r.args.request = r;
        r.return(200);
    }

When the context was destroyed, the collector could leave this graph in
the runtime, causing a worker abort in an assertion-enabled build or a
leak otherwise.  Cached request and response bodies had the same
ownership problem.  A stream callback capturing its session formed an
equivalent native cycle.

Add gc_mark callbacks symmetric with the class finalizers.  Stream
callbacks can now rely on normal cycle collection, so remove the special
teardown path that released them before the common exit-hook and pending
job processing.
nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c
nginx/t/js_qjs_gc_mark.t [new file with mode: 0644]