Skip to content

Commit

Permalink
Reset expired connections
Browse files Browse the repository at this point in the history
  • Loading branch information
iamluc committed Feb 6, 2023
1 parent 2f20ef1 commit c19de78
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import (
"sync/atomic"
"time"

_ "time/tzdata"

"github.com/ClickHouse/clickhouse-go/v2/contributors"
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
"github.com/ClickHouse/clickhouse-go/v2/lib/proto"
_ "time/tzdata"
)

type Conn = driver.Conn
Expand Down Expand Up @@ -253,7 +254,7 @@ func (ch *clickhouse) acquire(ctx context.Context) (conn *connect, err error) {
case <-timer.C:
return nil, ErrAcquireConnTimeout
case conn := <-ch.idle:
if conn.isBad() {
if conn.isBad() || time.Since(conn.connectedAt) >= ch.opt.ConnMaxLifetime {
conn.close()
if conn, err = ch.dial(ctx); err != nil {
select {
Expand Down

0 comments on commit c19de78

Please sign in to comment.