]> git.kaiwu.me - njs.git/commit
Modules: initialize the JS context of a completed subrequest
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 11 Nov 2026 01:46:20 +0000 (17:46 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Thu, 12 Nov 2026 22:29:31 +0000 (14:29 -0800)
commit76bf6406543d451bb86f1aeede23f74d671ce9be
tree29d557fbeedcc187251527e57a6d61d888b776e2
parent67b31155c79297de3219eb405e8b9807a7e63463
Modules: initialize the JS context of a completed subrequest

When a subrequest completed, its JS context was allocated by the
subrequest completion handler without ngx_js_ctx_init(), so the log and
the waiting events tree were not initialized.  If the subrequest had no
JS context of its own, a reply received by the parent could then use
it:

- readRequest*() on the reply inserted a caller event into the
  uninitialized tree;
- reading a js_set variable through reply.variables created an engine
  for the uninitialized context.

Both crashed with both engines.  The waiting events tree is missing
since 9de30135 (0.8.3), the log since 9b674412 (0.8.6).

Now the context is initialized as in ngx_http_js_init_vm().  Also,
deferred body reads are allowed only for the executing request, because
the body read state of a reply belongs to the subrequest.

Changed behaviour:
- readRequestText() and the other readRequest*() methods called on a
  subrequest reply throw TypeError.  They used to resolve with the body
  of the parent request, or to crash when the body had to be read.
nginx/ngx_http_js_module.c
nginx/t/js_http_runtime_isolation.t