From 71f4cb91340b656397eaaa356755b4a1e31c8010 Mon Sep 17 00:00:00 2001 From: Alexander Borisov Date: Thu, 15 Nov 2018 15:24:45 +0300 Subject: [PATCH] Node.js: added reference count increment for the Unit object. We increase the number to the Unit object so that it lives forever. This is necessary so that the garbage collector does not delete the Unit object. --- src/nodejs/unit-http/http_server.js | 2 ++ src/nodejs/unit-http/unit.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index ddacb420..b35ad259 100755 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -333,6 +333,8 @@ Server.prototype.run_events = function (server, req, res) { }); Promise.resolve().then(() => { + req.emit("finish"); + if (res.finished) { unit_lib.unit_response_end(res); } diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp index 97238834..bc6fc7db 100644 --- a/src/nodejs/unit-http/unit.cpp +++ b/src/nodejs/unit-http/unit.cpp @@ -111,6 +111,7 @@ napi_value Unit::create(napi_env env, napi_callback_info info) { Unit *obj; + napi_ref ref; napi_value target, cons, instance, jsthis; napi_status status; @@ -135,6 +136,11 @@ Unit::create(napi_env env, napi_callback_info info) goto failed; } + status = napi_create_reference(env, jsthis, 1, &ref); + if (status != napi_ok) { + goto failed; + } + return jsthis; } @@ -149,6 +155,11 @@ Unit::create(napi_env env, napi_callback_info info) goto failed; } + status = napi_create_reference(env, instance, 1, &ref); + if (status != napi_ok) { + goto failed; + } + return instance; failed: