Skip to content
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

refactor: fix undefined behavior and cleanup lock debugging code #3313

Open
wants to merge 3 commits into
base: 1.15.0-dev
Choose a base branch
from

Conversation

patricklodder
Copy link
Member

@patricklodder patricklodder commented Aug 11, 2023

This was triggered by and fixes #3305 (comment)

Removes undefined behavior by refactoring the way we destruct objects that track mutexes when debugging.

  1. Prevent UB from LockData custom destructor by making it implicit
  2. Replace the thread_specific_ptr holding the lock stack with a static map that stores it per thread.
  3. Clarify types by introducing new aliases making the code more readable
  4. Remove boost dependencies in favor of standard c++ for-loops, improving readability.

Backported from:

Note to testers: this functionality is only compiled in when using -DDEBUG_LOCKORDER, this is set with ./configure --enable-debug.

@patricklodder patricklodder added this to the 1.14.7 milestone Aug 11, 2023
@patricklodder patricklodder requested a review from a team August 11, 2023 13:48
@patricklodder patricklodder added this to 🚀 needs review in Review & merge board Aug 11, 2023
Copy link
Member

@chromatic chromatic left a comment

Choose a reason for hiding this comment

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

All tests pass on x86-64 Linux and my first skim of the code looks correct. I'll review the linked commits in more detail.

@xanimo
Copy link
Member

xanimo commented Aug 12, 2023

yeah no complaints re headless unit testing/qa on m2 👍

@xanimo
Copy link
Member

xanimo commented Aug 12, 2023

i did however fail a couple times in a for range 10 loop for qa on m2 but i think we'll be able to iron out that stuff now that debugging on dogecoin binaries is upgraded + the getmocktime stuff i'm looking into 👍

@patricklodder
Copy link
Member Author

patricklodder commented Aug 12, 2023

I'm having some issues reproducing deadlock detection on macOS w/ a set of wip code that I know to have the issue (and does trigger both before and after this PR on x86_64 linux w/ gcc12). Because the code in question is networking related, and of course we use a newer boost on macOS arm64 local builds, and we use clang instead of gcc... there can be a handful of potential causes.

Therefore I'm putting this back into draft, pending addition of a unit test. I'm sorry for opening this too soon.

@patricklodder patricklodder marked this pull request as draft August 12, 2023 11:22
@patricklodder patricklodder moved this from 🚀 needs review to 🔨needs rework in Review & merge board Aug 17, 2023
@patricklodder patricklodder removed this from the 1.14.7 milestone Feb 8, 2024
@patricklodder patricklodder changed the base branch from 1.14.7-dev to 1.15.0-dev February 28, 2024 19:28
@patricklodder
Copy link
Member Author

I've rebased this on top of 1.15.0-dev

patricklodder and others added 3 commits April 17, 2024 09:56
Removes undefined behavior by refactoring the way we destruct
objects that track mutexes when debugging.

1. Prevent UB from LockData custom destructor by making it implicit
2. Replace the thread_specific_ptr holding the lock stack with a
   static map that stores it per thread.

Also cleans up the aliasing to make the code better readable.

Backported from: 458992b
                 8d8921a
                 f511f61
                 58e6881
                 26c093a

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Co-authored-by: Wladimir J. van der Laan <laanwj@protonmail.com>
Removes boost dependencies in sync.cpp in favor of standard c++
for-loops, improving readability.
@patricklodder patricklodder marked this pull request as ready for review April 17, 2024 13:59
@patricklodder
Copy link
Member Author

I cherry-picked the unit test from 41b88e9, this is now ready for review.

I'm aware that there are multiple renames back and forth on this code that can influence picks; we can analyze these after this fix (as some of the picks in #3520 would make the UB problem come back; let's not do that)

@patricklodder patricklodder moved this from 🔨needs rework to 🚀 needs review in Review & merge board Apr 17, 2024
@xanimo
Copy link
Member

xanimo commented Apr 17, 2024

All unit and qa tests passed on x86_64-linux jammy. All unit tests passed on M2 but I encountered an issue with asyncore deprecation that I have to figure out. I don't think that issue should block this though.

@patricklodder
Copy link
Member Author

asyncore depreciation

Yes, we'll have to fix that separately - not related to this code. Would you mind filing an issue with a log?

@xanimo
Copy link
Member

xanimo commented Apr 18, 2024

asyncore depreciation

Yes, we'll have to fix that separately - not related to this code. Would you mind filing an issue with a log?

My pleasure.

@xanimo
Copy link
Member

xanimo commented Apr 18, 2024

ACK. #3524

@patricklodder patricklodder added this to the 1.15.0 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport cleanup Cleans up code
Projects
Review & merge board
🚀 needs review
Development

Successfully merging this pull request may close these issues.

Missing include for std::set in sync.cpp
4 participants