Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Madsen <amwebdk@gmail.com>2018-01-05 17:40:47 +0300
committerAndreas Madsen <amwebdk@gmail.com>2018-01-12 10:54:36 +0300
commit8479606a24ca12212b75e0febf92925b71ef8d50 (patch)
treea8585a851ec69830368aeb660c9a2c3605dd7f0b /lib/internal/async_hooks.js
parentc3fde98d4d2d920ce3df10a7668aa36bcfb49206 (diff)
async_hooks,http: set HTTPParser trigger to socket
This allows more easy tracking of where HTTP requests come from. Before this change the HTTPParser would have the HTTPServer as the triggerAsyncId. The HTTPParser will still have the executionAsyncId set to the HTTP Server so that information is still directly available. Indirectly, the TCP socket itself also has its triggerAsyncId set to the TCP Server. PR-URL: https://github.com/nodejs/node/pull/18003 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Diffstat (limited to 'lib/internal/async_hooks.js')
-rw-r--r--lib/internal/async_hooks.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js
index 2c43ccc3138..f1c98f13ac0 100644
--- a/lib/internal/async_hooks.js
+++ b/lib/internal/async_hooks.js
@@ -26,7 +26,7 @@ const async_wrap = process.binding('async_wrap');
* It has a fixed size, so if that is exceeded, calls to the native
* side are used instead in pushAsyncIds() and popAsyncIds().
*/
-const { async_hook_fields, async_id_fields } = async_wrap;
+const { async_id_symbol, async_hook_fields, async_id_fields } = async_wrap;
// Store the pair executionAsyncId and triggerAsyncId in a std::stack on
// Environment::AsyncHooks::ids_stack_ tracks the resource responsible for the
// current execution stack. This is unwound as each resource exits. In the case
@@ -248,6 +248,15 @@ function newUid() {
return ++async_id_fields[kAsyncIdCounter];
}
+function getOrSetAsyncId(object) {
+ if (object.hasOwnProperty(async_id_symbol)) {
+ return object[async_id_symbol];
+ }
+
+ return object[async_id_symbol] = newUid();
+}
+
+
// Return the triggerAsyncId meant for the constructor calling it. It's up to
// the user to safeguard this call and make sure it's zero'd out when the
// constructor is complete.
@@ -378,6 +387,7 @@ module.exports = {
disableHooks,
// Internal Embedder API
newUid,
+ getOrSetAsyncId,
getDefaultTriggerAsyncId,
defaultTriggerAsyncIdScope,
emitInit: emitInitScript,