2

我正在我的 node.js 项目(monorepo)中进行请求跟踪,并发现了一个名为“cls-hooked”的东西,它使用了异步钩子。因此,我只是将 cls-hooked 功能包装到适配器中,然后将其放入我在每个微服务中使用的共享库中。问题是在启动此类服务时:

node[35521]: ../src/async_wrap.cc:307:void node::SetupHooks(const FunctionCallbackInfo<v8::Value> &): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
 1: 0x100b9f32f node::Abort() (.cold.1) [/usr/local/opt/node@12/bin/node]
 2: 0x100080fc5 node::FatalError(char const*, char const*) [/usr/local/opt/node@12/bin/node]
 3: 0x100080e5a node::AppendExceptionLine(node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Message>, node::ErrorHandlingMode) [/usr/local/opt/node@12/bin/node]
 4: 0x100013952 node::SetupHooks(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/opt/node@12/bin/node]
 5: 0x1001d1496 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/usr/local/opt/node@12/bin/node]
 6: 0x1001d0b3a v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/opt/node@12/bin/node]
 7: 0x1001d0370 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/opt/node@12/bin/node]
 8: 0x100749039 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/opt/node@12/bin/node]

当我将适配器放入每个服务的代码中时 - 它就像一个魅力,但我不想在每个服务中复制这样的代码。有人能告诉我这个错误与异步钩子有关吗?是否甚至可以使用从 node_modules 加载的共享库中的异步挂钩功能或 cls 挂钩功能本身?

4

0 回答 0