addrmgr: make KnownAddress methods thread-safe #1763
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an alternative resolution for the data races in #1760. I'm proposing both solutions in case one is more palatable to the maintainers than the other. Note that the approach in this PR was taken by dcrd's fix in decred/dcrd@ad33b0e
This gives
KnownAddress
async.RWMutex
so the exported methods may safely access thena
(*wire.NetAddress
) andlastattempt
fields.The
AddrManager
is updated to lock the newKnownAddress
mutex before assigning tona
orlastattempt
.The other
KnownAddress
fields are only accessed byAddrManager
, using its own mutex for synchronization.This resolution requires no code changes in consumers like neutrino, just an update to the btcd module requirement. I've tested this with
btcwallet --testnet --usespv -d debug
, which uses neutrino and the affected code, using just areplace github.com/btcsuite/btcd => github.com/chappjc/btcd v0.22.0-beta.0.20211020165918-67e82a6dbe7f
.