Skip to content

Commit 36978ae

Browse files
committed
worker: handle detached MessagePort from a different context
When `worker.moveMessagePortToContext` is used, the async handle associated with the port, will be triggered more than needed (at least one more time) and with null data. That can be avoided by simply checking that the data is present and the port is not detached. Fixes: #49075 Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 6432060 commit 36978ae

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/node_messaging.cc

+5
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,11 @@ void MessagePort::OnMessage(MessageProcessingMode mode) {
795795

796796
size_t processing_limit;
797797
if (mode == MessageProcessingMode::kNormalOperation) {
798+
// Maybe the async handle was triggered empty or more than needed
799+
// (called twiced on a new context).
800+
if (GetTransferMode() == TransferMode::kDisallowCloneAndTransfer || !data_)
801+
return;
802+
798803
Mutex::ScopedLock(data_->mutex_);
799804
processing_limit = std::max(data_->incoming_messages_.size(),
800805
static_cast<size_t>(1000));

0 commit comments

Comments
 (0)