]> git.kaiwu.me - njs.git/commit
VM: preserve dependency code after failed module compilation
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 30 Sep 2026 06:06:42 +0000 (23:06 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 30 Sep 2026 18:56:11 +0000 (11:56 -0700)
commitc3e86ead170a5eee0bba90dc4c753438780441ba
tree5f08bcc28c3145866f7bbf3e679e7214f5cdee75
parentc08eafae17a90e1b72044b22b3d802f89a574abb
VM: preserve dependency code after failed module compilation

Commit fd54d52d freed all bytecode added after the parent module's
compilation checkpoint, including successfully compiled dependencies.
Those dependencies remain cached, so a later import in the same VM
executes freed bytecode.  This is reachable in the interactive shell
and in embedders that continue after a compilation error.

The fix is to remove eager bytecode cleanup while retaining removal of
the failed module from the cache so subsequent loads can retry.  Keep
the removed module and its name in the VM pool because cyclic
dependencies and code metadata can still reference them.  These
allocations are released when the VM is destroyed.

Add a shell regression test that retries a failed parent import and then
executes its cached dependency.
src/njs_generator.c
src/njs_generator.h
src/njs_module.c
src/njs_vm.c
test/js/module/compile_exception.js [new file with mode: 0644]
test/shell_test.exp