Skip to content

Commit 7ddfe4e

Browse files
committed
GODRIVER-2105 Fix Server cconfig onnection options being modified by createConnection. (#708)
1 parent 3541c8a commit 7ddfe4e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

x/mongo/driver/topology/server.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
179179
PoolMonitor: cfg.poolMonitor,
180180
}
181181

182-
connectionOpts := append(cfg.connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
182+
connectionOpts := make([]ConnectionOption, len(cfg.connectionOpts))
183+
copy(connectionOpts, cfg.connectionOpts)
184+
connectionOpts = append(connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
183185
s.pool, err = newPool(pc, connectionOpts...)
184186
if err != nil {
185187
return nil, err
@@ -649,7 +651,9 @@ func (s *Server) updateDescription(desc description.Server) {
649651
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
650652
// before the connection can be used for network operations.
651653
func (s *Server) createConnection() (*connection, error) {
652-
opts := []ConnectionOption{
654+
opts := make([]ConnectionOption, len(s.cfg.connectionOpts))
655+
copy(opts, s.cfg.connectionOpts)
656+
opts = append(opts,
653657
WithConnectTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
654658
WithReadTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
655659
WithWriteTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
@@ -662,8 +666,7 @@ func (s *Server) createConnection() (*connection, error) {
662666
// Override any monitors specified in options with nil to avoid monitoring heartbeats.
663667
WithMonitor(func(*event.CommandMonitor) *event.CommandMonitor { return nil }),
664668
withPoolMonitor(func(*event.PoolMonitor) *event.PoolMonitor { return nil }),
665-
}
666-
opts = append(s.cfg.connectionOpts, opts...)
669+
)
667670

668671
return newConnection(s.address, opts...)
669672
}

0 commit comments

Comments
 (0)