@@ -179,7 +179,9 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
179
179
PoolMonitor : cfg .poolMonitor ,
180
180
}
181
181
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 ))
183
185
s .pool , err = newPool (pc , connectionOpts ... )
184
186
if err != nil {
185
187
return nil , err
@@ -649,7 +651,9 @@ func (s *Server) updateDescription(desc description.Server) {
649
651
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
650
652
// before the connection can be used for network operations.
651
653
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 ,
653
657
WithConnectTimeout (func (time.Duration ) time.Duration { return s .cfg .heartbeatTimeout }),
654
658
WithReadTimeout (func (time.Duration ) time.Duration { return s .cfg .heartbeatTimeout }),
655
659
WithWriteTimeout (func (time.Duration ) time.Duration { return s .cfg .heartbeatTimeout }),
@@ -662,8 +666,7 @@ func (s *Server) createConnection() (*connection, error) {
662
666
// Override any monitors specified in options with nil to avoid monitoring heartbeats.
663
667
WithMonitor (func (* event.CommandMonitor ) * event.CommandMonitor { return nil }),
664
668
withPoolMonitor (func (* event.PoolMonitor ) * event.PoolMonitor { return nil }),
665
- }
666
- opts = append (s .cfg .connectionOpts , opts ... )
669
+ )
667
670
668
671
return newConnection (s .address , opts ... )
669
672
}
0 commit comments