Skip to content

Change of behaviour regarding micro tasks and Nan::AsyncProgressWorkerBase #1024

Description

@mmomtchev

I have noticed a significant change of behaviour that seems to have occurred between Node.js 26.3.0 and Node.js 26.4.0 when using Nan::AsyncProgressWorkerBase that does not call JavaScript in HandleOKCallback.

I have a manual Promise resolution using raw V8 calls that goes something like this:

void MyWorker::HandleOKCallback() {
  Nan::HandleScope scope;
  auto context = Nan::GetCurrentContext();
  // This comes from a persistent reference
  v8::Local<v8::Promise::Resolver> resolver = Nan::New(*resolver_handle);
  resolver->Resolve(context, this->ProduceRVal()).FromJust();
}

Since at least Node.js 12 and until Node.js 26.4.0 this code would result in the micro tasks queue being called after this function running the JS handlers of the promise.

Node.js 26.4.0 and later do not always call it, leaving the promise hanging in the air until something else calls it.

A simple fix is to simply call it manually, adding:

context->GetMicrotaskQueue()->PerformCheckpoint(isolate_);

I do not have a minimal repro and it might be difficult to do it since there are many other reasons why the micro tasks might get executed. In my case it happens only with mocha.

I am not very sure if a module should be calling the micro tasks directly and whether this change was intended or not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions