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

network: fix peerstore Get/Put races #6261

Merged

Conversation

algorandskiy
Copy link
Contributor

@algorandskiy algorandskiy commented Feb 21, 2025

Summary

Fix for a race condition seen in this test run

peerstore's GetConnectionWaitTime gets a peerstore entry, calculates number of recentConnectionTimes to remove and then calls popNElements that also gets the same entry from peerstore and attempts to remove number of entries calculated on the first copy.

Fixed by removing the addressData mutex and adding it to PeerStore itself. Otherwise all these PeerStore methods are racy.

Test Plan

Existing tests

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.18%. Comparing base (02bfca4) to head (f886280).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6261      +/-   ##
==========================================
- Coverage   51.80%   50.18%   -1.62%     
==========================================
  Files         644      644              
  Lines       86643    86644       +1     
==========================================
- Hits        44886    43484    -1402     
- Misses      38887    40219    +1332     
- Partials     2870     2941      +71     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

gmalouf
gmalouf previously approved these changes Feb 24, 2025
@algorandskiy algorandskiy added the p2p Work related to the p2p project label Feb 27, 2025
Copy link
Contributor

@cce cce left a comment

Choose a reason for hiding this comment

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

OK, big lock is easier for reader to understand, LGTM!

@algorandskiy algorandskiy changed the title network: fix peerstore stats update race network: fix peerstore Get/Put races Mar 3, 2025
@algorandskiy algorandskiy merged commit f468e57 into algorand:master Mar 3, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug-Fix p2p Work related to the p2p project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants