-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report: add missing locks for report_on_fatalerror accessors #32535
Conversation
Overlooked in 2fa74e3. Refs: nodejs#32207
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm assuming the same thing should be done in #32497?
@@ -129,12 +130,14 @@ static void SetSignal(const FunctionCallbackInfo<Value>& info) { | |||
} | |||
|
|||
static void ShouldReportOnFatalError(const FunctionCallbackInfo<Value>& info) { | |||
Mutex::ScopedLock lock(node::per_process::cli_options_mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will defining report_on_fatalerror
as std::atomic<bool>
be a better approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gireeshpunathil You could do that, but I doubt that it’s worth the extra complexity.
This makes threads running js (workers and main) all get mutex on access via the js setter/getter, but don't all accesses to that value after the intial CLI parsing need protection? Specifically, Line 409 in accc984
|
Do Set/GetFipsCrypto have the same issues? I didn't do a thorough review, I just did some grepping for some of the other process scope options, and they appear to be subject to the same problem as the on_error. @gireeshpunathil 's atomic suggestion seems a pretty good one for all bools, it makes it safer by shifting the responsibility to the variable to be safe, rather than to the users of the variable. Atomic won't work for types that are not trivially copyable, though, so strings will need to use the mutex. |
Landed in e06512b @sam-github If you want to switch these over to using atomics, I think that’s okay – most importantly, I’d like to be consistent, and I’d like to be explicit about using global mutable state when we’re doing it. And yes, the FIPS accessors look like they should also be protected by a mutex. |
@addaleax Did you see #32535 (comment)? Is no locking required on the other access? Btw, I tried atomic bools, they aren't supported by the options parser, and adding an entire new specialization for the options parser didn't seem worth it. cc: @gireeshpunathil |
@sam-github Yeah, as I said to @gireeshpunathil – it doesn’t seem worth the extra complexity. And yes, I think technically the other accesses need a mutex, too. Thinking about it, #31717 introduced a mechanism for this that might actually help a lot here – wrapping the per-process options struct in |
I like the #31717 approach, though I suspect it would break the options parsing even more thoroughly than atomics. On the plus side, it would also handle std::string (which can't be atomic), so that's a win. |
@sam-github To be clear, my suggestion is to wrap the entire struct in |
Overlooked in 2fa74e3. Refs: nodejs#32207 PR-URL: nodejs#32535 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Overlooked in 2fa74e3.
Refs: #32207
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes