Skip to content

Commit 79699df

Browse files
committed
GODRIVER-1695 Add timeout to IsMaster call in heartbeat
1 parent 750fe7d commit 79699df

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x/mongo/driver/topology/server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,12 @@ func (s *Server) heartbeat(conn *connection) (description.Server, *connection) {
502502
NewIsMaster().
503503
ClusterClock(s.cfg.clock).
504504
Deployment(driver.SingleConnectionDeployment{initConnection{conn}})
505-
err = op.Execute(ctx)
505+
506+
func() {
507+
timeoutCtx, cancel := context.WithTimeout(ctx, s.cfg.heartbeatTimeout)
508+
defer cancel()
509+
err = op.Execute(timeoutCtx)
510+
}()
506511
if err == nil {
507512
tmpDesc := op.Result(s.address)
508513
descPtr = &tmpDesc

0 commit comments

Comments
 (0)