Skip to content

node-api: TSFN user-provided Finalize callback executed before draining queue on aborted TSFN #60026

@KevinEady

Description

@KevinEady

It could be the case that the TSFN's context is needed in order to "clean up" data in the user-provided call_js callback.

Since the TSFN's user-provided finalizer is called prior to draining the queue, the finalizer may clean/delete the context, which would then be passed to the call_js_cb as an invalid pointer.

node/src/node_api.cc

Lines 424 to 431 in ce72fcc

void Finalize() {
v8::HandleScope scope(env->isolate);
if (finalize_cb) {
CallbackScope cb_scope(this);
env->CallFinalizer<false>(finalize_cb, finalize_data, context);
}
EmptyQueueAndDelete();
}

node/src/node_api.cc

Lines 297 to 302 in ce72fcc

void EmptyQueueAndDelete() {
for (; !queue.empty(); queue.pop()) {
call_js_cb(nullptr, nullptr, context, queue.front());
}
delete this;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    node-apiIssues and PRs related to the Node-API.

    Type

    No type

    Projects

    Status

    Has PR

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions