@@ -625,9 +625,6 @@ func (s *Server) check() (description.Server, error) {
625625 // Use the description from the connection handshake as the value for this check.
626626 s .rttMonitor .addSample (s .conn .isMasterRTT )
627627 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
631628 }
632629 }
633630
@@ -695,21 +692,28 @@ func (s *Server) check() (description.Server, error) {
695692 return emptyDescription , errCheckCancelled
696693 }
697694
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+
700707 switch converted := err .(type ) {
701708 case driver.Error :
702- topologyVersion = converted .TopologyVersion
709+ return converted .TopologyVersion
703710 case driver.WriteCommandError :
704711 if converted .WriteConcernError != nil {
705- topologyVersion = converted .WriteConcernError .TopologyVersion
712+ return converted .WriteConcernError .TopologyVersion
706713 }
707714 }
708715
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
713717}
714718
715719// String implements the Stringer interface.
0 commit comments