@@ -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.
651653func (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