@@ -625,9 +625,6 @@ func (s *Server) check() (description.Server, error) {
625
625
// Use the description from the connection handshake as the value for this check.
626
626
s .rttMonitor .addSample (s .conn .isMasterRTT )
627
627
descPtr = & s .conn .desc
628
- } else if connErr , ok := err .(ConnectionError ); ok {
629
- // Unwrap one layer so the code that extracts TopologyVersion in error cases works for handshake errors.
630
- err = connErr .Wrapped
631
628
}
632
629
}
633
630
@@ -695,21 +692,28 @@ func (s *Server) check() (description.Server, error) {
695
692
return emptyDescription , errCheckCancelled
696
693
}
697
694
698
- // An error occurred. Extract the topology version to use in the server description.
699
- var topologyVersion * description.TopologyVersion
695
+ // An error occurred. We reset the RTT monitor for all errors and return an Unknown description. The pool must also
696
+ // be cleared, but only after the description has already been updated, so that is handled by the caller.
697
+ topologyVersion := extractTopologyVersion (err )
698
+ s .rttMonitor .reset ()
699
+ return description .NewServerFromError (s .address , err , topologyVersion ), nil
700
+ }
701
+
702
+ func extractTopologyVersion (err error ) * description.TopologyVersion {
703
+ if ce , ok := err .(ConnectionError ); ok {
704
+ err = ce .Wrapped
705
+ }
706
+
700
707
switch converted := err .(type ) {
701
708
case driver.Error :
702
- topologyVersion = converted .TopologyVersion
709
+ return converted .TopologyVersion
703
710
case driver.WriteCommandError :
704
711
if converted .WriteConcernError != nil {
705
- topologyVersion = converted .WriteConcernError .TopologyVersion
712
+ return converted .WriteConcernError .TopologyVersion
706
713
}
707
714
}
708
715
709
- // We reset the RTT monitor for all errors and return an Unknown description. The pool must also be cleared, but
710
- // only after the description has already been updated, so that is handled by the caller.
711
- s .rttMonitor .reset ()
712
- return description .NewServerFromError (s .address , err , topologyVersion ), nil
716
+ return nil
713
717
}
714
718
715
719
// String implements the Stringer interface.
0 commit comments