Skip to content

Conversation

@bnoordhuis
Copy link
Member

Before this commit, sending a SIGUSR1 at program exit could trigger a
hard to reproduce race condition where v8::Debug::DebugBreak(isolate)
got called when the isolate was in the process of being torn down.

A similar race condition is in theory possible when sending signals
to two threads simultaneously but I haven't been able to reproduce
that myself (and I tried, oh how I tried.)

This commit fixes the race condition by turning node_isolate into
a std::atomic and using it as an ad hoc synchronization primitive
in places where that is necessary.

R=@indutny?

CI: https://ci.nodejs.org/job/node-test-pull-request/615/

@bnoordhuisbnoordhuis added c++ Issues and PRs that require attention from people who are familiar with C++. debugger labels Oct 26, 2015
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, our linter doesn't complain about this?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would it? It's a common C++ idiom.

@indutny
Copy link
Member

LGTM

@jasnell
Copy link
Member

LGTM

@bnoordhuis
Copy link
MemberAuthor

OS X... ../src/node.cc:89:10: fatal error: 'atomic' file not found. bangs head against table

@jasnell
Copy link
Member

@bnoordhuis .. ugh.

@bnoordhuis
Copy link
MemberAuthor

Hacked together a crummy workaround. I'll refine it further but first let's see if the basic approach works: https://ci.nodejs.org/job/node-test-pull-request/619/

@bnoordhuis
Copy link
MemberAuthor

@bnoordhuis
Copy link
MemberAuthor

Looking healthy. @indutny@jasnell Can I get a LGTM for 1b0ffcc?

@jasnell
Copy link
Member

Having to polyfill atomic makes me sad. Otherwise LGTM.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice polyfill you have here.

@indutny
Copy link
Member

LGTM, if it works

Before this commit, sending a SIGUSR1 at program exit could trigger a hard to reproduce race condition where `v8::Debug::DebugBreak(isolate)` got called when the isolate was in the process of being torn down. A similar race condition is in theory possible when sending signals to two threads simultaneously but I haven't been able to reproduce that myself (and I tried, oh how I tried.) This commit fixes the race condition by turning `node_isolate` into a `std::atomic` and using it as an ad hoc synchronization primitive in places where that is necessary. A bare minimum std::atomic polyfill is added for OS X because Apple wouldn't be Apple if things just worked out of the box. PR-URL: nodejs#3528 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
@bnoordhuisbnoordhuis deleted the fix-debugger-race branch October 27, 2015 12:02
@bnoordhuisbnoordhuis merged commit 53e64bb into nodejs:masterOct 27, 2015
@thefourtheye
Copy link
Contributor

A bare minimum std::atomic polyfill is added for OS X because Apple
wouldn't be Apple if things just worked out of the box.

lol

@jasnell
Copy link
Member

@bnoordhuis ... is this something that should go into LTS or not?

bnoordhuis added a commit that referenced this pull request Oct 28, 2015
Before this commit, sending a SIGUSR1 at program exit could trigger a hard to reproduce race condition where `v8::Debug::DebugBreak(isolate)` got called when the isolate was in the process of being torn down. A similar race condition is in theory possible when sending signals to two threads simultaneously but I haven't been able to reproduce that myself (and I tried, oh how I tried.) This commit fixes the race condition by turning `node_isolate` into a `std::atomic` and using it as an ad hoc synchronization primitive in places where that is necessary. A bare minimum std::atomic polyfill is added for OS X because Apple wouldn't be Apple if things just worked out of the box. PR-URL: #3528 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
@jasnell
Copy link
Member

Landed in v4.x-staging in c85736e

rvagg pushed a commit to rvagg/io.js that referenced this pull request Oct 29, 2015
Before this commit, sending a SIGUSR1 at program exit could trigger a hard to reproduce race condition where `v8::Debug::DebugBreak(isolate)` got called when the isolate was in the process of being torn down. A similar race condition is in theory possible when sending signals to two threads simultaneously but I haven't been able to reproduce that myself (and I tried, oh how I tried.) This commit fixes the race condition by turning `node_isolate` into a `std::atomic` and using it as an ad hoc synchronization primitive in places where that is necessary. A bare minimum std::atomic polyfill is added for OS X because Apple wouldn't be Apple if things just worked out of the box. PR-URL: nodejs#3528 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
@rvaggrvagg mentioned this pull request Oct 29, 2015
bnoordhuis added a commit that referenced this pull request Oct 29, 2015
Before this commit, sending a SIGUSR1 at program exit could trigger a hard to reproduce race condition where `v8::Debug::DebugBreak(isolate)` got called when the isolate was in the process of being torn down. A similar race condition is in theory possible when sending signals to two threads simultaneously but I haven't been able to reproduce that myself (and I tried, oh how I tried.) This commit fixes the race condition by turning `node_isolate` into a `std::atomic` and using it as an ad hoc synchronization primitive in places where that is necessary. A bare minimum std::atomic polyfill is added for OS X because Apple wouldn't be Apple if things just worked out of the box. PR-URL: #3528 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@bnoordhuis@indutny@jasnell@thefourtheye