You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/07/26 03:51:45 UTC

[skywalking-nodejs] 20/23: Delete the context when an event loop is done

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-nodejs.git

commit 2437e2a9ab896c79f4796fa644214e53c67725e0
Author: kezhenxu94 <ke...@163.com>
AuthorDate: Thu Jun 25 11:50:49 2020 +0800

    Delete the context when an event loop is done
---
 src/trace/context/ContextManager.ts | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/trace/context/ContextManager.ts b/src/trace/context/ContextManager.ts
index 3360031..e49bbb0 100644
--- a/src/trace/context/ContextManager.ts
+++ b/src/trace/context/ContextManager.ts
@@ -19,11 +19,19 @@
 
 import Context from '../../trace/context/Context';
 import SpanContext from '../../trace/context/SpanContext';
-import { executionAsyncId } from 'async_hooks';
+import { executionAsyncId, createHook } from 'async_hooks';
 
 class ContextManager {
   contextKeyedByAsyncId: { [asyncId: number]: Context } = {};
 
+  constructor() {
+    createHook({
+      destroy: (asyncId: number) => {
+        delete this.contextKeyedByAsyncId[asyncId];
+      },
+    }).enable();
+  }
+
   get current(): Context {
     const thisAsyncId = executionAsyncId();