async_wrap: call callback in destructor · nodejs/node@b663d2b · GitHub
Skip to content

Commit b663d2b

Browse files
trevnorrisrvagg
authored andcommitted
async_wrap: call callback in destructor
Call a user's callback to notify that the handle has been destroyed. Only pass the id of the AsyncWrap instance since the object no longer exists. The object that's being destructed should never be inspected within the callback or any time afterward. This commit make a breaking change. The init callback will now be passed arguments in the order of provider, id, parent. PR-URL: #3461 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent eccbec9 commit b663d2b

6 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/async-wrap-inl.h

Lines changed: 18 additions & 1 deletion

src/async-wrap.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static void SetupHooks(const FunctionCallbackInfo<Value>& args) {
131131
env->set_async_hooks_pre_function(args[1].As<Function>());
132132
if (args[2]->IsFunction())
133133
env->set_async_hooks_post_function(args[2].As<Function>());
134+
if (args[3]->IsFunction())
135+
env->set_async_hooks_destroy_function(args[3].As<Function>());
134136
}
135137

136138

@@ -156,6 +158,7 @@ static void Initialize(Local<Object> target,
156158
env->set_async_hooks_init_function(Local<Function>());
157159
env->set_async_hooks_pre_function(Local<Function>());
158160
env->set_async_hooks_post_function(Local<Function>());
161+
env->set_async_hooks_destroy_function(Local<Function>());
159162
}
160163

161164

src/async-wrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AsyncWrap : public BaseObject {
5151
ProviderType provider,
5252
AsyncWrap* parent = nullptr);
5353

54-
inline virtual ~AsyncWrap() override = default;
54+
inline virtual ~AsyncWrap();
5555

5656
inline ProviderType provider_type() const;
5757

src/env.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ namespace node {
236236
V(async_hooks_init_function, v8::Function) \
237237
V(async_hooks_pre_function, v8::Function) \
238238
V(async_hooks_post_function, v8::Function) \
239+
V(async_hooks_destroy_function, v8::Function) \
239240
V(binding_cache_object, v8::Object) \
240241
V(buffer_constructor_function, v8::Function) \
241242
V(buffer_prototype_object, v8::Object) \

test/parallel/test-async-wrap-disabled-propagate-parent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let cntr = 0;
1010
let server;
1111
let client;
1212

13-
function init(type, parent) {
13+
function init(type, id, parent) {
1414
if (parent) {
1515
cntr++;
1616
// Cannot assert in init callback or will abort.

test/parallel/test-async-wrap-propagate-parent.js

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)