From c8e53bdb3f24b6c778ccbc541dcf4834d81c6aca Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 7 Jul 2020 18:05:33 +0200 Subject: [PATCH 1/2] domain: fix unintentional deprecation warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 646e5a471766e27e8317bb changed the way that the domain hook callback is called. Previously, the callback was only used in the case that async_hooks were *not* being used (since domains already integrate with async hooks the way they should), and the corresponding deprecation warning also only emitted in that case. However, that commit didn’t move that condition along when the code was ported from C++ to JS. As a consequence, the domain hook callback was used when it wasn’t necessary to use it, and the deprecation warning emitted accidentally along with it. Refs: https://github.com/nodejs/node/commit/646e5a471766e27e8317bb54d1fd1d2c72cffb69#diff-9f21ce1b9d6d46fdd07b969e8a04e140L192 Refs: https://github.com/nodejs/node/commit/646e5a471766e27e8317bb54d1fd1d2c72cffb69#diff-e6db408e12db906ead6ddfac3de15a6fR119 Refs: https://github.com/nodejs/node/pull/33801#issuecomment-654744913 --- lib/internal/async_hooks.js | 2 +- test/parallel/test-domain-http-server.js | 4 +++- test/parallel/test-domain-implicit-binding.js | 2 ++ test/parallel/test-domain-implicit-fs.js | 2 ++ test/parallel/test-domain-multi.js | 2 ++ test/parallel/test-domain-promise.js | 2 ++ 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index fc894ebe4d773f..4ac4870781ce81 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -116,7 +116,7 @@ function callbackTrampoline(asyncId, cb, ...args) { emitBeforeNative(asyncId); let result; - if (typeof domain_cb === 'function') { + if (asyncId === 0 && typeof domain_cb === 'function') { ArrayPrototypeUnshift(args, cb); result = ReflectApply(domain_cb, this, args); } else { diff --git a/test/parallel/test-domain-http-server.js b/test/parallel/test-domain-http-server.js index 6168566334a11d..2f0c757a99df35 100644 --- a/test/parallel/test-domain-http-server.js +++ b/test/parallel/test-domain-http-server.js @@ -20,12 +20,14 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const domain = require('domain'); const http = require('http'); const assert = require('assert'); const debug = require('util').debuglog('test'); +process.on('warning', common.mustNotCall()); + const objects = { foo: 'bar', baz: {}, num: 42, arr: [1, 2, 3] }; objects.baz.asdf = objects; diff --git a/test/parallel/test-domain-implicit-binding.js b/test/parallel/test-domain-implicit-binding.js index 15f6685df93b7b..9f119a420368f0 100644 --- a/test/parallel/test-domain-implicit-binding.js +++ b/test/parallel/test-domain-implicit-binding.js @@ -6,6 +6,8 @@ const domain = require('domain'); const fs = require('fs'); const isEnumerable = Function.call.bind(Object.prototype.propertyIsEnumerable); +process.on('warning', common.mustNotCall()); + { const d = new domain.Domain(); diff --git a/test/parallel/test-domain-implicit-fs.js b/test/parallel/test-domain-implicit-fs.js index d5a6e79bc90734..c785ff75c67656 100644 --- a/test/parallel/test-domain-implicit-fs.js +++ b/test/parallel/test-domain-implicit-fs.js @@ -26,6 +26,8 @@ const common = require('../common'); const assert = require('assert'); const domain = require('domain'); +process.on('warning', common.mustNotCall()); + const d = new domain.Domain(); d.on('error', common.mustCall(function(er) { diff --git a/test/parallel/test-domain-multi.js b/test/parallel/test-domain-multi.js index 63701150f8c331..072f8e86bb077c 100644 --- a/test/parallel/test-domain-multi.js +++ b/test/parallel/test-domain-multi.js @@ -26,6 +26,8 @@ const common = require('../common'); const domain = require('domain'); const http = require('http'); +process.on('warning', common.mustNotCall()); + const a = domain.create(); a.enter(); // This will be our "root" domain diff --git a/test/parallel/test-domain-promise.js b/test/parallel/test-domain-promise.js index 704092522357fd..2a127f3d40272b 100644 --- a/test/parallel/test-domain-promise.js +++ b/test/parallel/test-domain-promise.js @@ -5,6 +5,8 @@ const domain = require('domain'); const fs = require('fs'); const vm = require('vm'); +process.on('warning', common.mustNotCall()); + { const d = domain.create(); From 0d44c74362c83d445459f60f8662326ffba3614a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 7 Jul 2020 19:11:45 +0200 Subject: [PATCH 2/2] fixup! domain: fix unintentional deprecation warning --- lib/internal/async_hooks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index 4ac4870781ce81..591c1c8e79d6c6 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -112,7 +112,7 @@ function useDomainTrampoline(fn) { } function callbackTrampoline(asyncId, cb, ...args) { - if (asyncId && hasHooks(kBefore)) + if (asyncId !== 0 && hasHooks(kBefore)) emitBeforeNative(asyncId); let result; @@ -123,7 +123,7 @@ function callbackTrampoline(asyncId, cb, ...args) { result = ReflectApply(cb, this, args); } - if (asyncId && hasHooks(kAfter)) + if (asyncId !== 0 && hasHooks(kAfter)) emitAfterNative(asyncId); return result;