Skip to content

Commit 2cf0ff2

Browse files
committed
fix(clickhouse): use atomic bool for closed flag
1 parent 901e11c commit 2cf0ff2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

clickhouse.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ type clickhouse struct {
105105
opt *Options
106106
connID int64
107107

108-
idle *idlePool
109-
open chan struct{}
108+
idle *idlePool
109+
open chan struct{}
110+
110111
closeOnce *sync.Once
111-
closed bool
112+
closed *atomic.Bool
112113
}
113114

114115
func (clickhouse) Contributors() []string {
@@ -282,7 +283,7 @@ func DefaultDialStrategy(ctx context.Context, connID int, opt *Options, dial Dia
282283
}
283284

284285
func (ch *clickhouse) acquire(ctx context.Context) (conn nativeTransport, err error) {
285-
if ch.closed {
286+
if ch.closed.Load() {
286287
return nil, ErrConnectionClosed
287288
}
288289

@@ -351,7 +352,7 @@ func (ch *clickhouse) release(conn nativeTransport, err error) {
351352
conn.freeBuffer()
352353
}
353354

354-
if ch.closed {
355+
if ch.closed.Load() {
355356
return
356357
}
357358

@@ -361,7 +362,7 @@ func (ch *clickhouse) release(conn nativeTransport, err error) {
361362
func (ch *clickhouse) Close() (err error) {
362363
ch.closeOnce.Do(func() {
363364
err = ch.idle.Close()
364-
ch.closed = true
365+
ch.closed.Store(true)
365366
})
366367

367368
return

0 commit comments

Comments
 (0)