Skip to content

Commit fc365e7

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 fc365e7

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

connection.go

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

296+
func (opts Opts) Copy() Opts {
297+
optsCopy := opts
298+
299+
return optsCopy
300+
}
301+
296302
// Connect creates and configures a new Connection.
297303
//
298304
// Address could be specified in following ways:
@@ -319,7 +325,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
319325
contextRequestId: 1,
320326
Greeting: &Greeting{},
321327
control: make(chan struct{}),
322-
opts: opts,
328+
opts: opts.Copy(),
323329
dec: newDecoder(&smallBuf{}),
324330
}
325331
maxprocs := uint32(runtime.GOMAXPROCS(-1))
@@ -344,9 +350,9 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
344350
}
345351
}
346352

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

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.Copy(),
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.Copy(),
9292
opts: opts,
9393
notify: notify,
9494
control: make(chan struct{}),

0 commit comments

Comments
 (0)