addrman: Add missing lock in Clear() (CAddrMan) #11585

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:missing-lock-in-addrman-clear changing 1 files +1 −0
  1. practicalswift commented at 9:38 AM on October 31, 2017: contributor

    Add missing lock in Clear() (CAddrMan).

    The variable vRandom is guarded by the mutex cs.

    Note to reviewers: Does this look correct? Should the lock cover the entire scope of the method, or should it be limited to cover only std::vector<int>().swap(vRandom);?

  2. addrman: Add missing lock in Clear() (CAddrMan)
    The variable vRandom is guarded by the mutex cs.
    3ab545d7f8
  3. fanquake added the label P2P on Oct 31, 2017
  4. promag commented at 2:44 PM on October 31, 2017: member

    ACK 3ab545d.

    I think all CAddrMan members should be guarded by cs, so LGTM as it is: https://github.com/bitcoin/bitcoin/blob/8335cb478183d800e274f6e96f9d7269ae584220/src/addrman.h#L184-L186

  5. practicalswift commented at 3:45 PM on October 31, 2017: contributor

    Thanks for the quick review @promag! @promag, you mean that all of the following should be guarded by cs? If so I think we might be missing some additional locks. Let me know and I'll investigate.

        //! last used nId
        int nIdCount;
    
        //! table with information about all nIds
        std::map<int, CAddrInfo> mapInfo;
    
        //! find an nId based on its network address
        std::map<CNetAddr, int> mapAddr;
    
        //! randomly-ordered vector of all nIds
        std::vector<int> vRandom;
    
        // number of "tried" entries
        int nTried;
    
        //! list of "tried" buckets
        int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
    
        //! number of (unique) "new" entries
        int nNew;
    
        //! list of "new" buckets
        int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE];
    
        //! last time Good was called (memory only)
        int64_t nLastGood;
    
    protected:
        //! secret key to randomize bucket select with
        uint256 nKey;
    
        //! Source of random numbers for randomization in inner loops
        FastRandomContext insecure_rand;
    
  6. promag commented at 3:50 PM on October 31, 2017: member
  7. practicalswift commented at 4:00 PM on October 31, 2017: contributor

    @promag I'll investigate! :-)

  8. practicalswift commented at 4:41 PM on October 31, 2017: contributor

    @promag You're right! The locking seems to be correct for the other CAddrMan members. Thanks!

  9. ryanofsky commented at 8:12 PM on November 1, 2017: member

    utACK 3ab545d7f8e979e2cabeff6f5f6f1afe94a5c195. CAddrMan::Clear is only called during initialization (during construction and deserialization) so it seems safe to add this lock. It would be good if the critical section comment was clearer about whether a lock is needed to access all class members or just some:

    https://github.com/bitcoin/bitcoin/blob/8335cb478183d800e274f6e96f9d7269ae584220/src/addrman.h#L185 @theuni probably knows more

  10. theuni commented at 8:32 PM on November 1, 2017: member

    utACK 3ab545d7f8e979e2cabeff6f5f6f1afe94a5c195. I believe the intention is for all public methods to lock the cs, and the privates ones don't need to. That would imply that all vars should be covered under the cs.

  11. TheBlueMatt commented at 7:06 PM on November 6, 2017: member

    utACK 3ab545d7f8e979e2cabeff6f5f6f1afe94a5c195

  12. MarcoFalke merged this on Nov 7, 2017
  13. MarcoFalke closed this on Nov 7, 2017

  14. MarcoFalke referenced this in commit 5aeaa9ccd1 on Nov 7, 2017
  15. PastaPastaPasta referenced this in commit 9251af6e47 on Dec 22, 2019
  16. PastaPastaPasta referenced this in commit 5e8faf616d on Jan 2, 2020
  17. PastaPastaPasta referenced this in commit c6bec0631d on Jan 4, 2020
  18. PastaPastaPasta referenced this in commit 990bbfaf68 on Jan 12, 2020
  19. PastaPastaPasta referenced this in commit c06494e098 on Jan 12, 2020
  20. PastaPastaPasta referenced this in commit b9bf573fe4 on Jan 12, 2020
  21. PastaPastaPasta referenced this in commit 5f556d0fb2 on Jan 12, 2020
  22. PastaPastaPasta referenced this in commit d18ea6417e on Jan 12, 2020
  23. PastaPastaPasta referenced this in commit aabb89de45 on Jan 12, 2020
  24. PastaPastaPasta referenced this in commit e1cbdef16c on Jan 16, 2020
  25. DeckerSU referenced this in commit b81d07b967 on Jun 7, 2020
  26. DeckerSU referenced this in commit 7d411ae2b4 on Jun 7, 2020
  27. Mixa84 referenced this in commit 31f22e8737 on Sep 9, 2020
  28. dimxy referenced this in commit 4d68c1accc on Sep 9, 2020
  29. TheComputerGenie referenced this in commit f7daa0b7ac on Oct 30, 2020
  30. TheComputerGenie referenced this in commit df8e111a61 on Oct 30, 2020
  31. TheComputerGenie referenced this in commit b757cad724 on Oct 31, 2020
  32. random-zebra referenced this in commit 007359a632 on Dec 5, 2020
  33. LarryRuane referenced this in commit 037b0d4320 on Mar 3, 2021
  34. ckti referenced this in commit 7a5fc97f02 on Mar 28, 2021
  35. practicalswift deleted the branch on Apr 10, 2021
  36. LarryRuane referenced this in commit 29eb55cc28 on Apr 13, 2021
  37. zkbot referenced this in commit 0e36226271 on Apr 17, 2021
  38. gades referenced this in commit 20246aa89e on Jul 1, 2021
  39. gades referenced this in commit 02228ac26f on Mar 25, 2022
  40. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me