Skip to content

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Apr 30, 2018

  • Add missing cs_args locks
  • Add Clang thread safety annotations for variables guarded by cs_args

@practicalswift
Copy link
Contributor Author

practicalswift commented May 12, 2018

Now includes a fix for a missing cs_args lock introduced in the recently merged PR #10267.

@practicalswift
Copy link
Contributor Author

Rebased!

@DrahtBot
Copy link
Contributor

The last travis run for this pull request was 53 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

@DrahtBot DrahtBot reopened this Jul 29, 2018
if (m_override_args.count("-includeconf") == 0) {
bool emptyIncludeConf;
{
LOCK(cs_args);
Copy link
Member

Choose a reason for hiding this comment

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

ReadConfigFiles is done once on start. Couldn't you just take the lock at the beginning of the method and remove those scoped locks further down in the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change caused the deadlock. Now reverted to previous version :-)

src/util.cpp Outdated
@@ -387,6 +388,7 @@ void ArgsManager::WarnForSectionOnlyArgs()
// if it's okay to use the default section for this network, don't worry
if (m_network == CBaseChainParams::MAIN) return;

LOCK(cs_args);
Copy link
Member

Choose a reason for hiding this comment

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

Just take the lock in the very first line of this method, or is there a specific reason that m_network shouldn't be protected?

@practicalswift
Copy link
Contributor Author

@MarcoFalke Thanks for reviewing! Feedback addressed. Please re-review :-)

@practicalswift
Copy link
Contributor Author

Added GUARDED_BY(cs_args) to m_available_args and m_network_only_args too :-)

src/util.cpp Outdated
@@ -304,6 +304,7 @@ class ArgsManagerHelper {
static inline bool GetNetBoolArg(const ArgsManager &am, const std::string& net_arg)
{
std::pair<bool,std::string> found_result(false,std::string());
LOCK(am.cs_args);
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to annotate this function and then take the lock where GetNetBoolArg is called (in GetChainName)

src/util.cpp Outdated
@@ -886,7 +891,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
}
// if there is an -includeconf in the override args, but it is empty, that means the user
// passed '-noincludeconf' on the command line, in which case we should not include anything
if (m_override_args.count("-includeconf") == 0) {
bool emptyIncludeConf = m_override_args.count("-includeconf") == 0;
if (emptyIncludeConf) {
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that was likely a left-over from a previous commit - a separate variable was needed to limit the scope of the lock. When the lock was moved higher up that was no longer needed but the variable was accidentally left around.

@maflcko
Copy link
Member

maflcko commented Aug 27, 2018

utACK, but could squash into two commits (1) add missing locks and (2) add lock annotations

@practicalswift
Copy link
Contributor Author

@MarcoFalke Good points. PR adjusted accordingly. Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Aug 29, 2018

POTENTIAL DEADLOCK DETECTED
Previous lock order was:
 (1)cs_args  util.cpp:874 (2)csPathCached  util.cpp:767
Current lock order is:
 (2)csPathCached  util.cpp:767 (1)cs_args  util.cpp:508

@practicalswift
Copy link
Contributor Author

@MarcoFalke Thanks! I'll investigate immediately!

@maflcko
Copy link
Member

maflcko commented Aug 29, 2018

Note that I reproduced this with --enable-debug in ./configure

@practicalswift
Copy link
Contributor Author

@MarcoFalke Strange! I always build with --enable-debug. Triggered by make check?

@maflcko
Copy link
Member

maflcko commented Aug 29, 2018

No, triggered by bitcoind or bitcoin-qt. It happens early on when the args and data dir are read.

src/util.cpp Outdated
m_config_args.clear();
{
LOCK(cs_args);
m_config_args.clear();
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just move those two lines after the GetConfigFile(); call? (And remove all scopes and re-locks?)

@practicalswift practicalswift force-pushed the guarded-by-cs_args branch 2 times, most recently from b16fb00 to 2d326da Compare August 29, 2018 20:31
@practicalswift practicalswift force-pushed the guarded-by-cs_args branch 3 times, most recently from 111354a to e492de8 Compare August 29, 2018 20:39
@practicalswift
Copy link
Contributor Author

@MarcoFalke Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Aug 29, 2018

This still fails travis for the same reason. Sorry, I guess my suggestion doesn't work.

@practicalswift
Copy link
Contributor Author

practicalswift commented Aug 30, 2018

@MarcoFalke Reverted again :-) Travis is now happy. Please re-review!

@maflcko maflcko merged commit 1e29379 into bitcoin:master Aug 30, 2018
maflcko pushed a commit that referenced this pull request Aug 30, 2018
… guarded by cs_args

1e29379 Fix potential deadlock (practicalswift)
d58dc9f Add lock annotations (cs_args) (practicalswift)
db5e9d3 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 17, 2020
… guarded by cs_args

Summary:
1e29379d69 Fix potential deadlock (practicalswift)
d58dc9f943 Add lock annotations (cs_args) (practicalswift)
db5e9d3c88 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

Backport of Core PR13126
bitcoin/bitcoin#13126

Completes T652

Test Plan:
  cmake -GNinja .. -DENABLE_WERROR=ON
  ninja check

Also run `build-werror` and `build-tsan` builds.

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc, markblundeberg

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: markblundeberg

Differential Revision: https://reviews.bitcoinabc.org/D4965
jonspock pushed a commit to jonspock/devault that referenced this pull request Oct 7, 2020
… guarded by cs_args

Summary:
1e29379d69 Fix potential deadlock (practicalswift)
d58dc9f943 Add lock annotations (cs_args) (practicalswift)
db5e9d3c88 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

Backport of Core PR13126
bitcoin/bitcoin#13126

Completes T652

Test Plan:
  cmake -GNinja .. -DENABLE_WERROR=ON
  ninja check

Also run `build-werror` and `build-tsan` builds.

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc, markblundeberg

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: markblundeberg

Differential Revision: https://reviews.bitcoinabc.org/D4965
jonspock pushed a commit to jonspock/devault that referenced this pull request Oct 10, 2020
… guarded by cs_args

Summary:
1e29379d69 Fix potential deadlock (practicalswift)
d58dc9f943 Add lock annotations (cs_args) (practicalswift)
db5e9d3c88 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

Backport of Core PR13126
bitcoin/bitcoin#13126

Completes T652

Test Plan:
  cmake -GNinja .. -DENABLE_WERROR=ON
  ninja check

Also run `build-werror` and `build-tsan` builds.

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc, markblundeberg

Reviewed By: jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: markblundeberg

Differential Revision: https://reviews.bitcoinabc.org/D4965
@practicalswift practicalswift deleted the guarded-by-cs_args branch April 10, 2021 19:35
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Jun 30, 2021
…riables guarded by cs_args

1e29379 Fix potential deadlock (practicalswift)
d58dc9f Add lock annotations (cs_args) (practicalswift)
db5e9d3 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

# Conflicts:
#	src/util/system.cpp
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Jul 2, 2021
…riables guarded by cs_args

1e29379 Fix potential deadlock (practicalswift)
d58dc9f Add lock annotations (cs_args) (practicalswift)
db5e9d3 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

# Conflicts:
#	src/util/system.cpp
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Jul 2, 2021
…riables guarded by cs_args

1e29379 Fix potential deadlock (practicalswift)
d58dc9f Add lock annotations (cs_args) (practicalswift)
db5e9d3 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

# Conflicts:
#	src/util/system.cpp
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 22, 2022
…riables guarded by cs_args

1e29379 Fix potential deadlock (practicalswift)
d58dc9f Add lock annotations (cs_args) (practicalswift)
db5e9d3 Add missing locks (cs_args) (practicalswift)

Pull request description:

  * Add missing `cs_args` locks
  * Add Clang thread safety annotations for variables guarded by `cs_args`

Tree-SHA512: bc562dbddf24a287bcf9bf902bc930f942f260a94e5c8ec4d190f7f2ddac448ed3d52acadaf9fc1c81a5cbff2c171c52c18ba0804eeb03f699d70394e1c977c5

# Conflicts:
#	src/util/system.cpp
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants