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: https://github.com/nodejs/node/pull/25911 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
39eca841c3
commit
b1cc1af2bd
@ -533,6 +533,11 @@ MessagePort* MessagePort::New(
|
|||||||
if (data) {
|
if (data) {
|
||||||
port->Detach();
|
port->Detach();
|
||||||
port->data_ = std::move(data);
|
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;
|
port->data_->owner_ = port;
|
||||||
// If the existing MessagePortData object had pending messages, this is
|
// If the existing MessagePortData object had pending messages, this is
|
||||||
// the easiest way to run that queue.
|
// the easiest way to run that queue.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user