-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ type MetricsTracer interface { | |
OpenedConnection(network.Direction, crypto.PubKey, network.ConnectionState, ma.Multiaddr) | ||
ClosedConnection(network.Direction, time.Duration, network.ConnectionState, ma.Multiaddr) | ||
CompletedHandshake(time.Duration, network.ConnectionState, ma.Multiaddr) | ||
FailedDialing(ma.Multiaddr, error) | ||
FailedDialing(ma.Multiaddr, error, error) | ||
DialCompleted(success bool, totalDials int) | ||
DialRankingDelay(d time.Duration) | ||
UpdatedBlackHoleFilterState(name string, state blackHoleState, nextProbeAfter int, successFraction float64) | ||
|
@@ -216,18 +216,28 @@ func (m *metricsTracer) CompletedHandshake(t time.Duration, cs network.Connectio | |
connHandshakeLatency.WithLabelValues(*tags...).Observe(t.Seconds()) | ||
} | ||
|
||
func (m *metricsTracer) FailedDialing(addr ma.Multiaddr, err error) { | ||
func (m *metricsTracer) FailedDialing(addr ma.Multiaddr, dialErr error, cause error) { | ||
transport := metricshelper.GetTransport(addr) | ||
e := "other" | ||
if errors.Is(err, context.Canceled) { | ||
e = "canceled" | ||
} else if errors.Is(err, context.DeadlineExceeded) { | ||
// dial deadline exceeded or the the parent contexts deadline exceeded | ||
if errors.Is(dialErr, context.DeadlineExceeded) || errors.Is(cause, context.DeadlineExceeded) { | ||
e = "deadline" | ||
} else if errors.Is(dialErr, context.Canceled) { | ||
// dial was cancelled. | ||
if errors.Is(cause, context.Canceled) { | ||
// parent context was canceled | ||
e = "application canceled" | ||
} else if errors.Is(cause, errConcurrentDialSuccessful) { | ||
e = "canceled: concurrent dial successful" | ||
} else { | ||
// something else | ||
e = "canceled: other" | ||
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. Do we expect this to happen at all? 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. Don't think so. Didnt happen on my kubo node. I ran it for about an hour |
||
} | ||
} else { | ||
nerr, ok := err.(net.Error) | ||
nerr, ok := dialErr.(net.Error) | ||
if ok && nerr.Timeout() { | ||
e = "timeout" | ||
} else if strings.Contains(err.Error(), "connect: connection refused") { | ||
} else if strings.Contains(dialErr.Error(), "connect: connection refused") { | ||
e = "connection refused" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.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.