From bbe84149083db23ba356b15d820d29e7798bfe5a Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 3 Feb 2019 20:20:52 +0100 Subject: [PATCH] worker: add mutex lock to MessagePort ctor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/node_messaging.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 6e8e3e8ad76e03..9952043f7b4c34 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -533,6 +533,11 @@ MessagePort* MessagePort::New( if (data) { port->Detach(); port->data_ = std::move(data); + + // This lock is here to avoid race conditions with the `owner_` read + // in AddToIncomingQueue(). (This would likely be unproblematic without it, + // but it's better to be safe than sorry.) + Mutex::ScopedLock lock(port->data_->mutex_); port->data_->owner_ = port; // If the existing MessagePortData object had pending messages, this is // the easiest way to run that queue.