Skip to content

network: fix peerstore Get/Put races#6261

Merged
algorandskiy merged 6 commits intoalgorand:masterfrom
algorandskiy:pavel/fix-peerstore-pop-race
Mar 3, 2025
Merged

network: fix peerstore Get/Put races#6261
algorandskiy merged 6 commits intoalgorand:masterfrom
algorandskiy:pavel/fix-peerstore-pop-race

Conversation

@algorandskiy
Copy link
Copy Markdown
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

@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
@algorandskiy algorandskiy deleted the pavel/fix-peerstore-pop-race branch March 16, 2026 20:05
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