Skip to content

p2p: fix infinite loop in dnsaddr resolution#5926

Merged
algorandskiy merged 1 commit intoalgorand:feature/p2pfrom
algorandskiy:pavel/p2p-dnsaddr-fix
Feb 2, 2024
Merged

p2p: fix infinite loop in dnsaddr resolution#5926
algorandskiy merged 1 commit intoalgorand:feature/p2pfrom
algorandskiy:pavel/p2p-dnsaddr-fix

Conversation

@algorandskiy
Copy link
Copy Markdown
Contributor

Summary

dnsaddr.Iterate() is not tolerate to cycles. Added max attempts to prevent infinite looping.

Test Plan

Added a unit test.

@algorandskiy algorandskiy added Bug-Fix p2p Work related to the p2p project labels Feb 1, 2024
@algorandskiy algorandskiy self-assigned this Feb 1, 2024
mockController{},
func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { return nil },
)
return true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally this would check the error returned by Iterate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why? I want to check no infinite loops and not resolution errors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You made the decision to return an error when max hops are reached. In my view, it only makes sense to test that return value here, rather than ignoring it

Comment thread network/p2p/dnsaddr/resolve.go
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a8e2254) 55.98% compared to head (8137156) 55.99%.

Additional details and impacted files
@@               Coverage Diff               @@
##           feature/p2p    #5926      +/-   ##
===============================================
+ Coverage        55.98%   55.99%   +0.01%     
===============================================
  Files              482      482              
  Lines            68057    68062       +5     
===============================================
+ Hits             38103    38114      +11     
+ Misses           27347    27343       -4     
+ Partials          2607     2605       -2     

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

Copy link
Copy Markdown
Contributor

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

I left a test suggestion, but it's not serious enough to be a blocker

mockController{},
func(dnsaddr multiaddr.Multiaddr, entries []multiaddr.Multiaddr) error { return nil },
)
return true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You made the decision to return an error when max hops are reached. In my view, it only makes sense to test that return value here, rather than ignoring it

if resolver == nil {
return errors.New("passed controller has no resolvers Iterate")
}
const maxHops = 100
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 100 - i.e. this feels more like 10 is sufficient..?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do not know what is actual max limit

@algorandskiy algorandskiy merged commit ba8b2cd into algorand:feature/p2p Feb 2, 2024
@algorandskiy algorandskiy deleted the pavel/p2p-dnsaddr-fix branch March 16, 2026 20:06
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.

3 participants