-
Notifications
You must be signed in to change notification settings - Fork 340
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
fix: retry user agent get from libp2p peerstore #2482
Changes from 5 commits
0636a59
601c7c0
46bb19d
23a1107
642f07e
5fab077
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -884,7 +884,19 @@ func (s *Service) Ping(ctx context.Context, addr ma.Multiaddr) (rtt time.Duratio | |
// provides it. It ignores the default libp2p user agent string | ||
// "github.com/libp2p/go-libp2p" and returns empty string in that case. | ||
func (s *Service) peerUserAgent(peerID libp2ppeer.ID) string { | ||
v, err := s.host.Peerstore().Get(peerID, "AgentVersion") | ||
var ( | ||
v interface{} | ||
err error | ||
) | ||
// Peerstore may not contain all keys and values right after the connections is created. | ||
// This retry mechanism ensures more reliable user agent propagation. | ||
for deadline := time.Now().Add(2 * time.Second); time.Now().Before(deadline); { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my only question would be: could it be that the retry mechanism would make some context with deadline in the enclosing context expire? func (k *Kad) connect(ctx context.Context, peer swarm.Address, ma ma.Multiaddr) error {
ctx, cancel := context.WithTimeout(ctx, peerConnectionAttemptTimeout)
defer cancel()
switch i, err := k.p2p.Connect(ctx, ma); { kademlia dial has a 5 seconds timeout in this case. so the user agent printing might delay this and make it expire. I wonder if we could either decrease this timespan to be shorter so that it becomes insignificant comparing to the total connection context deadline or simply do this polling in a different goroutine and print it eventually in an unrelated logline that would have the overlay and user agent together. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. I've added context handling to the function. |
||
v, err = s.host.Peerstore().Get(peerID, "AgentVersion") | ||
if err == nil { | ||
break | ||
} | ||
time.Sleep(50 * time.Millisecond) | ||
} | ||
if err != nil { | ||
// error is ignored as user agent is informative only | ||
return "" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: *connection