Skip to content

Commit

Permalink
GODRIVER-2105 Fix Server cconfig onnection options being modified by …
Browse files Browse the repository at this point in the history
…createConnection. (#708)
  • Loading branch information
matthewdale committed Jul 30, 2021
1 parent 3541c8a commit 7ddfe4e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions x/mongo/driver/topology/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
PoolMonitor: cfg.poolMonitor,
}

connectionOpts := append(cfg.connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
connectionOpts := make([]ConnectionOption, len(cfg.connectionOpts))
copy(connectionOpts, cfg.connectionOpts)
connectionOpts = append(connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
s.pool, err = newPool(pc, connectionOpts...)
if err != nil {
return nil, err
Expand Down Expand Up @@ -649,7 +651,9 @@ func (s *Server) updateDescription(desc description.Server) {
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
// before the connection can be used for network operations.
func (s *Server) createConnection() (*connection, error) {
opts := []ConnectionOption{
opts := make([]ConnectionOption, len(s.cfg.connectionOpts))
copy(opts, s.cfg.connectionOpts)
opts = append(opts,
WithConnectTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
WithReadTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
WithWriteTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
Expand All @@ -662,8 +666,7 @@ func (s *Server) createConnection() (*connection, error) {
// Override any monitors specified in options with nil to avoid monitoring heartbeats.
WithMonitor(func(*event.CommandMonitor) *event.CommandMonitor { return nil }),
withPoolMonitor(func(*event.PoolMonitor) *event.PoolMonitor { return nil }),
}
opts = append(s.cfg.connectionOpts, opts...)
)

return newConnection(s.address, opts...)
}
Expand Down

0 comments on commit 7ddfe4e

Please sign in to comment.