]> git.kaiwu.me - njs.git/commit
Modules: bind QuickJS native views to their context lifetime
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 10 Nov 2026 20:17:46 +0000 (12:17 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 11 Nov 2026 21:33:45 +0000 (13:33 -0800)
commitaaaf571211d59e7b7365f7e038c6dca7d9536e08
treef21dc87d0027b34a85d658883fb827d7331f9d79
parent9719fc9a8f0e35bc18560726f395ca9af7e968a0
Modules: bind QuickJS native views to their context lifetime

HTTP and stream views can outlive their request or connection pool
in a reused runtime.  Detaching only the root object leaves variables,
headers, forms and replies with dangling native pointers.  Direct
session accessors and cold body getters can dereference detached roots,
while populated request caches hide their expiry.

Share a runtime-owned revocable token across each binding and its
views.  Reject expired access before native dereferences, including
cache access, without retaining pools or copying native data.
Keep reply tokens tied to the originating subrequest operation so
completed replies remain usable until the parent binding is detached.

The header and variable lifetime gap dates back to 201b1276, which
introduces QuickJS integration.  RequestForm uses the same unguarded
model since 0ffc96df.  Extracted JS values and stream callback flags
remain independent; RequestForm remains a guarded request-bound view.
nginx/ngx_http_js_module.c
nginx/ngx_js.c
nginx/ngx_js.h
nginx/ngx_stream_js_module.c
nginx/t/js_http_lifetime_scopes.t [new file with mode: 0644]
nginx/t/js_http_object_lifetime.t [new file with mode: 0644]
nginx/t/stream_js_object_lifetime.t [new file with mode: 0644]