Skip to content

Commit a20f033

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 a20f033

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Diff for: connection.go

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

296+
// Copy returns the copy of an Opts object.
297+
// Beware that Notify channel, Logger and Handle are not copied.
298+
func (opts Opts) Copy() Opts {
299+
optsCopy := opts
300+
301+
return optsCopy
302+
}
303+
296304
// Connect creates and configures a new Connection.
297305
//
298306
// Address could be specified in following ways:
@@ -319,7 +327,7 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
319327
contextRequestId: 1,
320328
Greeting: &Greeting{},
321329
control: make(chan struct{}),
322-
opts: opts,
330+
opts: opts.Copy(),
323331
dec: newDecoder(&smallBuf{}),
324332
}
325333
maxprocs := uint32(runtime.GOMAXPROCS(-1))
@@ -344,9 +352,9 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
344352
}
345353
}
346354

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

Diff for: 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{}),

Diff for: 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)