Skip to content

worker_threads.moveMessagePortToContext results in an abort #38499

Closed
@zyscoder

Description

@zyscoder

What steps will reproduce the bug?

Setup a node instance,

» node

and run the following javascript code line by line.

worker_threads = require('worker_threads');msgChannel = new worker_threads.MessageChannel();
msgChannel.port2.close();
worker_threads.moveMessagePortToContext(msgChannel.port2,{});

Then an abort occurs.
Noticed that paste these codes to REPL all at once seems cannot trigger this abort. Run these codes line by line pls.

How often does it reproduce? Is there a required condition?

This problem can always be triggered following the steps above.

What is the expected behavior?

If any error occurs, an exception or other similar error-reporting stuff should be thrown. There is no reason to abort the whole node process.

What do you see instead?

» node
Welcome to Node.js v17.0.0-pre.
Type ".help" for more information.
> worker_threads = require('worker_threads');msgChannel = new worker_threads.MessageChannel();
MessageChannel {
  port1: MessagePort [EventTarget] {
    active: true,
    refed: false,
    [Symbol(kEvents)]: SafeMap(2) [Map] {
      'newListener' => [Object],
      'removeListener' => [Object]
    },
    [Symbol(events.maxEventTargetListeners)]: 10,
    [Symbol(events.maxEventTargetListenersWarned)]: false,
    [Symbol(kNewListener)]: [Function (anonymous)],
    [Symbol(kRemoveListener)]: [Function (anonymous)],
    [Symbol(nodejs.internal.kCurrentlyReceivingPorts)]: undefined
  },
  port2: MessagePort [EventTarget] {
    active: true,
    refed: false,
    [Symbol(kEvents)]: SafeMap(2) [Map] {
      'newListener' => [Object],
      'removeListener' => [Object]
    },
    [Symbol(events.maxEventTargetListeners)]: 10,
    [Symbol(events.maxEventTargetListenersWarned)]: false,
    [Symbol(kNewListener)]: [Function (anonymous)],
    [Symbol(kRemoveListener)]: [Function (anonymous)],
    [Symbol(nodejs.internal.kCurrentlyReceivingPorts)]: undefined
  }
}
> msgChannel.port2.close();
undefined
> worker_threads.moveMessagePortToContext(msgChannel.port2,{});
/home/zys/Toolchains/node/node[59534]: ../src/node_messaging.cc:1068:static void node::worker::MessagePort::MoveToContext(const FunctionCallbackInfo<v8::Value> &): Assertion `(port) != nullptr' failed.
 1: 0x3623e04 node::DumpBacktrace(_IO_FILE*) [/home/zys/Toolchains/node/node]
 2: 0x37bb92e node::Abort() [/home/zys/Toolchains/node/node]
 3: 0x37bb3f8  [/home/zys/Toolchains/node/node]
 4: 0x38c8dac node::worker::MessagePort::MoveToContext(v8::FunctionCallbackInfo<v8::Value> const&) [/home/zys/Toolchains/node/node]
 5: 0x3ebd0d8 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/home/zys/Toolchains/node/node]
 6: 0x3ebadb9  [/home/zys/Toolchains/node/node]
 7: 0x3eb8d1d  [/home/zys/Toolchains/node/node]
 8: 0x5a08759  [/home/zys/Toolchains/node/node]
[1]    59534 abort (core dumped)  /home/zys/Toolchains/node/node

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++Issues and PRs that require attention from people who are familiar with C++.confirmed-bugIssues with confirmed bugs.good first issueIssues that are suitable for first-time contributors.workerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions