Skip to content

Commit e70aa30

Browse files
committed
worker: add mutex lock to MessagePort ctor
Automated tooling for race condition detection reports this as a possible problem. It’s unlikely that something bad would happen here (beyond maybe calling `TriggerAsync()` twice), but adding this should be okay. PR-URL: #25911 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2009f18 commit e70aa30

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
@@ -533,6 +533,11 @@ MessagePort* MessagePort::New(
533533
if (data) {
534534
port->Detach();
535535
port->data_ = std::move(data);
536+
537+
// This lock is here to avoid race conditions with the `owner_` read
538+
// in AddToIncomingQueue(). (This would likely be unproblematic without it,
539+
// but it's better to be safe than sorry.)
540+
Mutex::ScopedLock lock(port->data_->mutex_);
536541
port->data_->owner_ = port;
537542
// If the existing MessagePortData object had pending messages, this is
538543
// the easiest way to run that queue.

0 commit comments

Comments
 (0)