Skip to content

Commit 15ac5cf

Browse files
author
Divjot Arora
authored
GODRIVER-1740 Add check for nil TopologyVersion in Server.Equal() (#519)
1 parent f29d01d commit 15ac5cf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mongo/description/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,13 @@ func (s Server) Equal(other Server) bool {
423423
return false
424424
}
425425

426-
if s.TopologyVersion.CompareToIncoming(other.TopologyVersion) != 0 {
427-
return false
426+
// If TopologyVersion is nil for both servers, CompareToIncoming will return -1 because it assumes that the
427+
// incoming response is newer. We want the descriptions to be considered equal in this case, though, so an
428+
// explicit check is required.
429+
if s.TopologyVersion == nil && other.TopologyVersion == nil {
430+
return true
428431
}
429-
430-
return true
432+
return s.TopologyVersion.CompareToIncoming(other.TopologyVersion) == 0
431433
}
432434

433435
func sliceStringEqual(a []string, b []string) bool {

0 commit comments

Comments
 (0)