From 9d99e848a403f7c6f2657e67572d41e1f109a28f Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 29 Oct 2026 18:46:09 -0700 Subject: [PATCH] Modules: fix top-level await handling in QuickJS Previously, the result of module evaluation was awaited, but the outcome was not checked: - a rejected top-level await was silently ignored; - a top-level await on a promise settled only by a timer or another asynchronous event remained pending. In both cases the module was considered loaded without its exports and each request failed later with a misleading "js function not found" error. Now, both cases fail the context creation with an explicit error. The issue was introduced in 9a5430e6 (0.9.5). --- nginx/ngx_js.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index b7d04a5d..5167a6d9 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -1202,12 +1202,21 @@ ngx_qjs_clone(ngx_js_ctx_t *ctx, ngx_js_loc_conf_t *cf, void *external) } rc = ngx_qjs_await(cx, ctx->log, &rv); - JS_FreeValue(cx, rv); - if (rc == NGX_ERROR) { + if (rc == NGX_ERROR || JS_IsException(rv)) { + JS_FreeValue(cx, rv); ngx_qjs_log_exception(engine, ctx->log, "await exception"); goto failed; } + if (JS_PromiseState(cx, rv) == JS_PROMISE_PENDING) { + JS_FreeValue(cx, rv); + ngx_log_error(NGX_LOG_ERR, ctx->log, 0, + "js top-level await is not settled"); + goto failed; + } + + JS_FreeValue(cx, rv); + return engine; failed: -- 2.47.3