@@ -180,8 +180,7 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
180
180
PoolMonitor : cfg .poolMonitor ,
181
181
}
182
182
183
- connectionOpts := make ([]ConnectionOption , len (cfg .connectionOpts ))
184
- copy (connectionOpts , cfg .connectionOpts )
183
+ connectionOpts := copyConnectionOpts (cfg .connectionOpts )
185
184
connectionOpts = append (connectionOpts , withErrorHandlingCallback (s .ProcessHandshakeError ))
186
185
s .pool = newPool (pc , connectionOpts ... )
187
186
s .publishServerOpeningEvent (s .address )
@@ -590,8 +589,7 @@ func (s *Server) updateDescription(desc description.Server) {
590
589
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
591
590
// before the connection can be used for network operations.
592
591
func (s * Server ) createConnection () (* connection , error ) {
593
- opts := make ([]ConnectionOption , len (s .cfg .connectionOpts ))
594
- copy (opts , s .cfg .connectionOpts )
592
+ opts := copyConnectionOpts (s .cfg .connectionOpts )
595
593
opts = append (opts ,
596
594
WithConnectTimeout (func (time.Duration ) time.Duration { return s .cfg .heartbeatTimeout }),
597
595
WithReadTimeout (func (time.Duration ) time.Duration { return s .cfg .heartbeatTimeout }),
@@ -609,6 +607,12 @@ func (s *Server) createConnection() (*connection, error) {
609
607
return newConnection (s .address , opts ... )
610
608
}
611
609
610
+ func copyConnectionOpts (opts []ConnectionOption ) []ConnectionOption {
611
+ optsCopy := make ([]ConnectionOption , len (opts ))
612
+ copy (optsCopy , opts )
613
+ return optsCopy
614
+ }
615
+
612
616
func (s * Server ) setupHeartbeatConnection () error {
613
617
conn , err := s .createConnection ()
614
618
if err != nil {
0 commit comments