From 3d9d1ade2a361f408b116c5bafb2fcd560310f9c Mon Sep 17 00:00:00 2001 From: Gerhard Stoebich <18708370+Flarna@users.noreply.github.com> Date: Sun, 5 May 2019 21:29:32 +0200 Subject: async_hooks: don't reuse resource in HttpAgent As discussed in https://github.com/nodejs/diagnostics/issues/248, https://github.com/nodejs/node/pull/21313 and https://docs.google.com/document/d/1g8OrG5lMIUhRn1zbkutgY83MiTSMx-0NHDs8Bf-nXxM/preview reusing the resource object is a blocker for landing a resource based async hooks API and get rid of the promise destroy hook. This PR ensures that HttpAgent uses the a new resource object in case the socket handle gets reused. PR-URL: https://github.com/nodejs/node/pull/27581 Reviewed-By: Matteo Collina Reviewed-By: Rich Trott --- src/async_wrap.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/async_wrap.cc') diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 8cb30a6f6a..e11ce07681 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -410,13 +410,26 @@ void AsyncWrap::PopAsyncIds(const FunctionCallbackInfo& args) { void AsyncWrap::AsyncReset(const FunctionCallbackInfo& args) { + CHECK(args[0]->IsObject()); + AsyncWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); + + Local resource = args[0].As(); double execution_async_id = - args[0]->IsNumber() ? args[0].As()->Value() : kInvalidAsyncId; - wrap->AsyncReset(execution_async_id); + args[1]->IsNumber() ? args[1].As()->Value() : kInvalidAsyncId; + wrap->AsyncReset(resource, execution_async_id); } + +void AsyncWrap::GetProviderType(const FunctionCallbackInfo& args) { + AsyncWrap* wrap; + args.GetReturnValue().Set(AsyncWrap::PROVIDER_NONE); + ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); + args.GetReturnValue().Set(wrap->provider_type()); +} + + void AsyncWrap::EmitDestroy() { AsyncWrap::EmitDestroy(env(), async_id_); // Ensure no double destroy is emitted via AsyncReset(). @@ -437,6 +450,7 @@ Local AsyncWrap::GetConstructorTemplate(Environment* env) { tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "AsyncWrap")); env->SetProtoMethod(tmpl, "getAsyncId", AsyncWrap::GetAsyncId); env->SetProtoMethod(tmpl, "asyncReset", AsyncWrap::AsyncReset); + env->SetProtoMethod(tmpl, "getProviderType", AsyncWrap::GetProviderType); env->set_async_wrap_ctor_template(tmpl); } return tmpl; -- cgit v1.2.3