Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port.postMessage with another closed port results in an abort #56362

Open
zyscoder opened this issue Dec 25, 2024 · 0 comments
Open

port.postMessage with another closed port results in an abort #56362

zyscoder opened this issue Dec 25, 2024 · 0 comments
Labels
worker Issues and PRs related to Worker support.

Comments

@zyscoder
Copy link

Version

v22.11.0

Platform

Linux u24vm 6.8.0-50-generic #51-Ubuntu SMP PREEMPT_DYNAMIC Sat Nov  9 17:58:29 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

worker_threads

What steps will reproduce the bug?

Setup a node instance,

» node

and run the following javascript code.

worker_threads = require('worker_threads');
msg1 = new worker_threads.MessageChannel();
msg1.port1.close();
msg2 = new worker_threads.MessageChannel();
msg2.port1.postMessage(msg1.port1);

Then the node instance occurs an abort.

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

This abort can always be triggered following the steps above.

What is the expected behavior? Why is that the expected behavior?

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

What do you see instead?

» node                                                                                                        
Welcome to Node.js v22.11.0.
Type ".help" for more information.
>
> worker_threads = require('worker_threads');
{
  isMainThread: true,
  MessagePort: [Function: MessagePort],
  MessageChannel: [Function: MessageChannel],
  markAsUncloneable: [Function: markAsUncloneable],
  markAsUntransferable: [Function: markAsUntransferable],
  isMarkedAsUntransferable: [Function: isMarkedAsUntransferable],
  moveMessagePortToContext: [Function: moveMessagePortToContext],
  receiveMessageOnPort: [Function: receiveMessageOnPort],
  resourceLimits: {},
  postMessageToThread: [AsyncFunction: postMessageToThread],
  threadId: 0,
  SHARE_ENV: Symbol(nodejs.worker_threads.SHARE_ENV),
  Worker: [class Worker extends EventEmitter],
  parentPort: null,
  workerData: null,
  BroadcastChannel: [class BroadcastChannel extends EventTarget],
  setEnvironmentData: [Function: setEnvironmentData],
  getEnvironmentData: [Function: getEnvironmentData]
}
> msg1 = 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(kHandlers)]: SafeMap(0) [Map] {},
    [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(kHandlers)]: SafeMap(0) [Map] {},
    [Symbol(kNewListener)]: [Function (anonymous)],
    [Symbol(kRemoveListener)]: [Function (anonymous)],
    [Symbol(nodejs.internal.kCurrentlyReceivingPorts)]: undefined
  }
}
> msg1.port1.close();
undefined
> msg2 = 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(kHandlers)]: SafeMap(0) [Map] {},
    [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(kHandlers)]: SafeMap(0) [Map] {},
    [Symbol(kNewListener)]: [Function (anonymous)],
    [Symbol(kRemoveListener)]: [Function (anonymous)],
    [Symbol(nodejs.internal.kCurrentlyReceivingPorts)]: undefined
  }
}
> msg2.port1.postMessage(msg1.port1);
[1]    1295254 segmentation fault (core dumped)  node

Additional information

No response

@marco-ippolito marco-ippolito added the worker Issues and PRs related to Worker support. label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

2 participants