Skip to content
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

GODRIVER-1489 Correctly unwrap topology version for monitor check errors #446

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions x/mongo/driver/topology/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,6 @@ func (s *Server) check() (description.Server, error) {
// Use the description from the connection handshake as the value for this check.
s.rttMonitor.addSample(s.conn.isMasterRTT)
descPtr = &s.conn.desc
} else if connErr, ok := err.(ConnectionError); ok {
// Unwrap one layer so the code that extracts TopologyVersion in error cases works for handshake errors.
err = connErr.Wrapped
}
}

Expand Down Expand Up @@ -695,21 +692,28 @@ func (s *Server) check() (description.Server, error) {
return emptyDescription, errCheckCancelled
}

// An error occurred. Extract the topology version to use in the server description.
var topologyVersion *description.TopologyVersion
// An error occurred. We reset the RTT monitor for all errors and return an Unknown description. The pool must also
// be cleared, but only after the description has already been updated, so that is handled by the caller.
topologyVersion := extractTopologyVersion(err)
s.rttMonitor.reset()
return description.NewServerFromError(s.address, err, topologyVersion), nil
}

func extractTopologyVersion(err error) *description.TopologyVersion {
if ce, ok := err.(ConnectionError); ok {
err = ce.Wrapped
}

switch converted := err.(type) {
case driver.Error:
topologyVersion = converted.TopologyVersion
return converted.TopologyVersion
case driver.WriteCommandError:
if converted.WriteConcernError != nil {
topologyVersion = converted.WriteConcernError.TopologyVersion
return converted.WriteConcernError.TopologyVersion
}
}

// We reset the RTT monitor for all errors and return an Unknown description. The pool must also be cleared, but
// only after the description has already been updated, so that is handled by the caller.
s.rttMonitor.reset()
return description.NewServerFromError(s.address, err, topologyVersion), nil
return nil
}

// String implements the Stringer interface.
Expand Down