From: Dmitry Volyntsev Date: Wed, 16 Nov 2022 02:38:49 +0000 (-0800) Subject: Modules: fixed Fetch Response prototype reinitialization. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/postgres_fdw.c?a=commitdiff_plain;h=d4b87eeb486818b9a00733ffcf3ec80f91d97bab;p=njs.git Modules: fixed Fetch Response prototype reinitialization. Previously, since 446a1cb64a6a (0.7.7), when at least one js_import directive was declared in both HTTP and Stream, ngx.fetch() returned inapproriate response in Stream. The prototype for Response object was created two times for HTTP and STREAM, but the second initialization of global variable with the index of the Response() prototype overwrites the first value with a different value. This caused a problem in Stream code which manifested itself as a `Stream flags` object returned as a result of ngx.fetch() call instead of a Response instance. The fix is to ensure that shared prototypes like a Response prototype have indentical index value in all the modules. This fixes #596 issue on Github. --- diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 831593da..7a816498 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -953,16 +953,21 @@ ngx_js_init_conf_vm(ngx_conf_t *cf, ngx_js_conf_t *conf, } } - rc = externals_init(cf, conf); - if (rc != NGX_OK) { - return NGX_ERROR; - } + /* + * Core prototypes must be inited before externals_init() because + * the core prototype ids have to be identical in all the modules. + */ rc = ngx_js_core_init(conf->vm, cf->log); if (njs_slow_path(rc != NJS_OK)) { return NGX_ERROR; } + rc = externals_init(cf, conf); + if (rc != NGX_OK) { + return NGX_ERROR; + } + end = start + size; rc = njs_vm_compile(conf->vm, &start, end);