Skip to content

Make debug_sync regex more robust #1944

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

On windows the symbol names appear to sometimes be truncated,
which causes the symbol name to not include the ::new at the end.
This causes the regex to mis-match and track the wrong location
for the mutex construction, leading to bogus lockorder violations.

For example, in testing the following symbol name appeared on
Windows, without the function name itself:

lightning::debug_sync::RwLock<std::collections::hash::map::HashMap<lightning::chain::transaction::OutPoint,lightning::chain::chainmonitor::MonitorHolder<lightning::util::enforcing_trait_impls::EnforcingSigner>,std::collections::hash::map::RandomState> >::

This will allow us to change the module regex match in debug_sync
to make it more robust.
On windows the symbol names appear to sometimes be truncated,
which causes the symbol name to not include the `::new` at the end.
This causes the regex to mis-match and track the wrong location
for the mutex construction, leading to bogus lockorder violations.

For example, in testing the following symbol name appeared on
Windows, without the function name itself:

`lightning::debug_sync::RwLock<std::collections::hash::map::HashMap<lightning::chain::transaction::OutPoint,lightning::chain::chainmonitor::MonitorHolder<lightning::util::enforcing_trait_impls::EnforcingSigner>,std::collections::hash::map::RandomState> >::`
@TheBlueMatt TheBlueMatt force-pushed the 2022-01-lockorder-windows-robust branch from e65cc30 to ab46f6b Compare January 10, 2023 06:48
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2023

Codecov Report

Base: 90.75% // Head: 90.72% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (ab46f6b) compared to base (197a47a).
Patch coverage: 90.16% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1944      +/-   ##
==========================================
- Coverage   90.75%   90.72%   -0.03%     
==========================================
  Files          96       97       +1     
  Lines       50135    50135              
  Branches    50135    50135              
==========================================
- Hits        45498    45484      -14     
- Misses       4637     4651      +14     
Impacted Files Coverage Δ
lightning/src/lib.rs 100.00% <ø> (ø)
lightning/src/sync/debug_sync.rs 98.33% <ø> (ø)
lightning/src/sync/test_lockorder_checks.rs 90.16% <90.16%> (ø)
lightning/src/chain/onchaintx.rs 95.17% <0.00%> (-0.21%) ⬇️
lightning/src/ln/functional_tests.rs 96.90% <0.00%> (-0.20%) ⬇️
lightning/src/chain/channelmonitor.rs 90.98% <0.00%> (-0.10%) ⬇️
lightning/src/ln/channelmanager.rs 86.68% <0.00%> (+0.02%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

Looks happy to me. We shouldn't get any false-positive construction sites from what I can see.

@@ -77,7 +77,7 @@ fn get_construction_location(backtrace: &Backtrace) -> String {
// Find the first frame that is after `debug_sync` (or that is in our tests) and use
// that as the mutex construction site. Note that the first few frames may be in
// the `backtrace` crate, so we have to ignore those.
let sync_mutex_constr_regex = regex::Regex::new(r"lightning.*debug_sync.*new").unwrap();
let sync_mutex_constr_regex = regex::Regex::new(r"lightning.*debug_sync").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a trailing .* to match the locks type (and new when it is not truncated)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, is_match "Returns true if and only if there is a match for the regex in the string given." ie not if the match is the string but if there is a match in the string.

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for this.

@TheBlueMatt TheBlueMatt merged commit fad52d8 into lightningdevkit:main Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants