Skip to content

Commit

Permalink
Merge branch 'master' into unpool
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Songhurst committed Mar 19, 2018
2 parents a98713d + 8bbf58c commit 9d4b874
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion conn_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ConnPool struct {
connStr string
maxConn int
pool []*Conn
done chan bool
poolGuard chan bool
poolMutex sync.Mutex
cleanupTicker *time.Ticker
Expand Down Expand Up @@ -58,6 +59,7 @@ func NewConnPool(connStr string) (*ConnPool, error) {
cleanupTicker: time.NewTicker(poolCleanupInterval),
connCount: 0,
spParamsCache: NewParamsCache(),
done: make(chan bool, 1),
}
conn, err := p.newConn()
if err != nil {
Expand All @@ -67,8 +69,11 @@ func NewConnPool(connStr string) (*ConnPool, error) {
p.poolGuard = make(chan bool, p.maxConn)
p.addToPool(conn)
go func() {
for _ = range p.cleanupTicker.C {
select {
case <-p.cleanupTicker.C:
p.cleanup()
case <-p.done:
return
}
}()
return p, nil
Expand Down Expand Up @@ -191,6 +196,7 @@ func (p *ConnPool) Close() {
conn.close()
}
p.pool = nil
close(p.done)
}

func (p *ConnPool) cleanup() {
Expand Down

0 comments on commit 9d4b874

Please sign in to comment.