Skip to content

Conversation

w0xlt
Copy link
Contributor

@w0xlt w0xlt commented Jan 18, 2022

This PR is related to #19303 and gets rid of the RecursiveMutex cs_mapLocalHost.

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #20196 (net: fix GetListenPort() to derive the proper port by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Approach ACK 3e05ab9.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Approach ACK 3e05ab9

Going commit wise:

  1. The renaming of the mutex cs_mapLocalHost -> map_localhost_mutex, is an improvement, in my opinion.
  2. The type of map_localhost_mutex is changed from RecursiveMutex to Mutex. I checked through the codebase where map_localhost_mutex is used for any instances of recursive lockings, and I found none. Also, I was able to compile this PR without any UB warnings successfully. So I think it’s safe to convert the type of this mutex from RecursiveMutex to Mutex.

I shall ACK this PR as soon as this suggestion by @hebasto is addressed.

w0xlt added 2 commits January 19, 2022 07:04
-BEGIN VERIFY SCRIPT-
s() { sed -i 's/cs_mapLocalHost/g_maplocalhost_mutex/g' $1; }
s src/net.cpp
s src/net.h
s src/rpc/net.cpp
s src/test/net_tests.cpp
-END VERIFY SCRIPT-
@w0xlt w0xlt force-pushed the mutex-mapLocalHost branch from 3e05ab9 to 5e7e4c9 Compare January 19, 2022 10:31
Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK 5e7e4c9

Changes since my last review:

  • map_localhost_mutex -> g_maplocalhost_mutex.

The updated PR compiled successfully on Ubuntu 20.04.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

ACK 5e7e4c9

Checked that within all critical sections that are protected by g_maplocalhost_mutex, there is no chance another one is called, i.e. a regular Mutex is sufficient.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK 5e7e4c9, I have reviewed the code and it looks OK, I agree it can be merged.

In particular, I've verified that there are no recursive mutex locking on the path GetLocal() --> CNetAddr::GetReachabilityFrom() --> CNetAddr::IsRoutable().


A script in the "scripted-diff" commit could be more robust:

sed -i 's/cs_mapLocalHost/g_maplocalhost_mutex/g' -- $(git grep --files-with-matches 'cs_mapLocalHost')

@maflcko maflcko merged commit 1824644 into bitcoin:master Jan 20, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 20, 2022
@w0xlt w0xlt deleted the mutex-mapLocalHost branch January 24, 2022 14:59
@bitcoin bitcoin locked and limited conversation to collaborators Jan 24, 2023
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.

6 participants