Qjs exit hook#959
Merged
Merged
Conversation
7d54d27 to
08bdad5
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements the QuickJS exit hook functionality by adding support for njs.on('exit', callback) which allows JavaScript code to register exit hooks that are called when the context is destroyed.
Key changes include:
- Convert core class ID definitions from #define macros to enums for better type safety
- Implement a new
njsglobal object with exit hook functionality - Add test coverage for the exit hook feature
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/qjs.h | Converts class ID macros to enum and adds exit hook function declaration |
| src/qjs.c | Implements core exit hook functionality including the njs object and event handlers |
| nginx/t/js_exit.t | Adds new test file for HTTP exit hook functionality |
| nginx/t/stream_js_exit.t | Removes QuickJS skip condition to enable stream exit hook tests |
| nginx/ngx_stream_js_module.c | Refactors string handling to use JS_ToCStringLen directly |
| nginx/ngx_qjs_fetch.c | Updates string conversion calls to use pool-based allocation |
| nginx/ngx_js_shared_dict.c | Updates string handling for shared dictionary operations |
| nginx/ngx_js.h | Updates function signature and adds QuickJS conditional compilation |
| nginx/ngx_js.c | Integrates exit hook calls and updates string conversion implementation |
| nginx/ngx_http_js_module.c | Updates string conversion calls and fixes cleanup handler type |
| external/njs_shell.c | Adds exit hook call to engine destruction |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
2797465 to
db255bc
Compare
Previously in QuickJS engine, fields allocated from memory pool linked to QuickJS engine lifetime were stored in nginx data structs. This causes a heap-use-after-free if QuickJS engine is destroyed earlier than a last access from nginx. For example, it becomes visible when moving NJS cleanup handler from pool->cleanup to r->cleanup. The fix is to only store references in nginx objects allocated from nginx memory pool.
This closes nginx#955 issue on Github.
db255bc to
5abdc98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.