-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
swarm: track dial cancellation reason #2532
Conversation
3665bd0
to
055cec0
Compare
p2p/net/swarm/swarm_metrics.go
Outdated
if errors.Is(cause, errParentContextCanceled) { | ||
// parent was canceled | ||
e = "canceled" | ||
} else if errors.Is(cause, context.Canceled) { |
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.
This looks brittle. Should we have a separate cause for this?
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.
Makes sense. That would be cleaner.
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.
I removed errParentContextCanceled
and added errConcurrentDialSuccessful
.
Now if the cause is context.Canceled
it necessarily means the application cancelled the context and if the cause is errConcurrentDialSuccessful
it means a concurrent dial succeeded.
e = "canceled: dial successful" | ||
} else { | ||
// something else | ||
e = "canceled: other" |
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.
Do we expect this to happen at all?
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.
Don't think so. Didnt happen on my kubo node. I ran it for about an hour
p2p/net/swarm/dial_sync.go
Outdated
delete(ds.dials, p) | ||
} | ||
}() | ||
return ad.dial(ctx) | ||
conn, err := ad.dial(ctx) // updated err is used in defered func |
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.
Are you sure this works? Isn't :=
creating a new err
here?
Why do we have this defer
anyway, there's only a single return from this function.
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.
err is declared in the beginning of the method so this will assign to it.
Anyway, I will remove the defer. That is confusing.
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.
removed it.
bb7cc59
to
69b01a6
Compare
ad.refCnt-- | ||
if ad.refCnt == 0 { | ||
if err == nil { | ||
ad.cancelCause(errConcurrentDialSuccessful) |
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.
Why? What would happen if we're just dialing one address, and that dial is successful?
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.
That dial would have succeeded so the context cancellation has no effect on that dial. That method would have returned.
There are two options:
- We set call
cancelCause(nil)
and live with the brittle check thaterrors.Is(Cause(err), context.Canceled)
signals concurrent successful dial. Here we override actual cancelations of parent context with errParentCanceled. This is the strategy in 055cec0 commit. - Is the latest commit. We explicitly signal
errConcurrentDialSuccessful
when err is nil. In case the dial succeeds, this is not a problem since we will not callFailedDial
for tracking metrics in that case.
closes: #2321