Skip to content

Commit

Permalink
internal: copy opts on Connect
Browse files Browse the repository at this point in the history
The copy is not an honest deepcopy because, for example, copying logger
or channel will break the logic.

Part of #120
  • Loading branch information
DifferentialOrange authored and oleg-jukovec committed Nov 30, 2022
1 parent 47871bd commit c34bd35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ type SslOpts struct {
Ciphers string
}

// Clone returns a copy of the Opts object.
func (opts Opts) Clone() Opts {
optsCopy := opts

return optsCopy
}

// Connect creates and configures a new Connection.
//
// Address could be specified in following ways:
Expand All @@ -319,7 +326,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
contextRequestId: 1,
Greeting: &Greeting{},
control: make(chan struct{}),
opts: opts,
opts: opts.Clone(),
dec: newDecoder(&smallBuf{}),
}
maxprocs := uint32(runtime.GOMAXPROCS(-1))
Expand All @@ -344,9 +351,9 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
}
}

if opts.RateLimit > 0 {
conn.rlimit = make(chan struct{}, opts.RateLimit)
if opts.RLimitAction != RLimitDrop && opts.RLimitAction != RLimitWait {
if conn.opts.RateLimit > 0 {
conn.rlimit = make(chan struct{}, conn.opts.RateLimit)
if conn.opts.RLimitAction != RLimitDrop && conn.opts.RLimitAction != RLimitWait {
return nil, errors.New("RLimitAction should be specified to RLimitDone nor RLimitWait")
}
}
Expand Down
2 changes: 1 addition & 1 deletion connection_pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsPool) (co

connPool = &ConnectionPool{
addrs: make([]string, 0, len(addrs)),
connOpts: connOpts,
connOpts: connOpts.Clone(),
opts: opts,
state: unknownState,
done: make(chan struct{}),
Expand Down
2 changes: 1 addition & 1 deletion multi/multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (c
connOpts.Notify = notify
connMulti = &ConnectionMulti{
addrs: addrs,
connOpts: connOpts,
connOpts: connOpts.Clone(),
opts: opts,
notify: notify,
control: make(chan struct{}),
Expand Down

0 comments on commit c34bd35

Please sign in to comment.