Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2020-02-13 18:31:05 +0300
committerAnna Henningsen <anna@addaleax.net>2020-02-13 22:53:36 +0300
commit303e2fdc598cbc82af401f12f3cc9169ed31598b (patch)
treef995ebea324b64ff3dbb54bae68533f319ed4828 /src/node_process_object.cc
parentb32fa7bcc69aec0acb63792c799a22eeae7424c6 (diff)
src: wrap HostPort in ExclusiveAccess
I found it exceedingly hard to figure out if there is a race condition where one thread reads the inspector agent's HostPort's properties while another modifies them concurrently. I think the answer is "no, there isn't" but with this commit use sites are forced to unwrap the object (and acquire the mutex in the process), making it a great deal easier to reason about correctness. PR-URL: https://github.com/nodejs/node/pull/31717 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'src/node_process_object.cc')
-rw-r--r--src/node_process_object.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/node_process_object.cc b/src/node_process_object.cc
index 7cf8c125009..ddbb58abe53 100644
--- a/src/node_process_object.cc
+++ b/src/node_process_object.cc
@@ -51,7 +51,8 @@ static void ProcessTitleSetter(Local<Name> property,
static void DebugPortGetter(Local<Name> property,
const PropertyCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
- int port = env->inspector_host_port()->port();
+ ExclusiveAccess<HostPort>::Scoped host_port(env->inspector_host_port());
+ int port = host_port->port();
info.GetReturnValue().Set(port);
}
@@ -60,7 +61,8 @@ static void DebugPortSetter(Local<Name> property,
const PropertyCallbackInfo<void>& info) {
Environment* env = Environment::GetCurrent(info);
int32_t port = value->Int32Value(env->context()).FromMaybe(0);
- env->inspector_host_port()->set_port(static_cast<int>(port));
+ ExclusiveAccess<HostPort>::Scoped host_port(env->inspector_host_port());
+ host_port->set_port(static_cast<int>(port));
}
static void GetParentProcessId(Local<Name> property,