Skip to content

Commit f433cf2

Browse files
internal: copy opts on Connect
The copy is not an honest deepcopy because, for example, copying logger or channel will break the logic. Part of #120
1 parent 71ce8d1 commit f433cf2

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

connection.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ type SslOpts struct {
293293
Ciphers string
294294
}
295295

296+
// Clone returns a copy of the Opts object.
297+
func (opts Opts) Clone() Opts {
298+
optsCopy := opts
299+
300+
return optsCopy
301+
}
302+
296303
// Connect creates and configures a new Connection.
297304
//
298305
// Address could be specified in following ways:
@@ -319,7 +326,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
319326
contextRequestId: 1,
320327
Greeting: &Greeting{},
321328
control: make(chan struct{}),
322-
opts: opts,
329+
opts: opts.Clone(),
323330
dec: newDecoder(&smallBuf{}),
324331
}
325332
maxprocs := uint32(runtime.GOMAXPROCS(-1))
@@ -344,9 +351,9 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
344351
}
345352
}
346353

347-
if opts.RateLimit > 0 {
348-
conn.rlimit = make(chan struct{}, opts.RateLimit)
349-
if opts.RLimitAction != RLimitDrop && opts.RLimitAction != RLimitWait {
354+
if conn.opts.RateLimit > 0 {
355+
conn.rlimit = make(chan struct{}, conn.opts.RateLimit)
356+
if conn.opts.RLimitAction != RLimitDrop && conn.opts.RLimitAction != RLimitWait {
350357
return nil, errors.New("RLimitAction should be specified to RLimitDone nor RLimitWait")
351358
}
352359
}

connection_pool/connection_pool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsPool) (co
125125

126126
connPool = &ConnectionPool{
127127
addrs: make([]string, 0, len(addrs)),
128-
connOpts: connOpts,
128+
connOpts: connOpts.Clone(),
129129
opts: opts,
130130
state: unknownState,
131131
done: make(chan struct{}),

multi/multi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func ConnectWithOpts(addrs []string, connOpts tarantool.Opts, opts OptsMulti) (c
8888
connOpts.Notify = notify
8989
connMulti = &ConnectionMulti{
9090
addrs: addrs,
91-
connOpts: connOpts,
91+
connOpts: connOpts.Clone(),
9292
opts: opts,
9393
notify: notify,
9494
control: make(chan struct{}),

0 commit comments

Comments
 (0)