mirror of
https://github.com/jackc/pgx.git
synced 2025-04-27 21:25:53 +00:00
Rename CleanupChan to CleanupDone
This commit is contained in:
parent
3eb5432c47
commit
fdfc783345
@ -1,6 +1,6 @@
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
* Add PgConn.CleanupChan so connection pools can determine when async close is complete
|
* Add PgConn.CleanupDone so connection pools can determine when async close is complete
|
||||||
|
|
||||||
# 1.6.4 (July 29, 2020)
|
# 1.6.4 (July 29, 2020)
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func closeConn(t testing.TB, conn *pgconn.PgConn) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
require.NoError(t, conn.Close(ctx))
|
require.NoError(t, conn.Close(ctx))
|
||||||
select {
|
select {
|
||||||
case <-conn.CleanupChan():
|
case <-conn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
|
18
pgconn.go
18
pgconn.go
@ -90,7 +90,7 @@ type PgConn struct {
|
|||||||
multiResultReader MultiResultReader
|
multiResultReader MultiResultReader
|
||||||
contextWatcher *ctxwatch.ContextWatcher
|
contextWatcher *ctxwatch.ContextWatcher
|
||||||
|
|
||||||
cleanupChan chan struct{}
|
cleanupDone chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
// Connect establishes a connection to a PostgreSQL server using the environment and connString (in URL or DSN format)
|
||||||
@ -203,7 +203,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
|
|||||||
pgConn := new(PgConn)
|
pgConn := new(PgConn)
|
||||||
pgConn.config = config
|
pgConn.config = config
|
||||||
pgConn.wbuf = make([]byte, 0, wbufLen)
|
pgConn.wbuf = make([]byte, 0, wbufLen)
|
||||||
pgConn.cleanupChan = make(chan struct{})
|
pgConn.cleanupDone = make(chan struct{})
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
network, address := NetworkAddress(fallbackConfig.Host, fallbackConfig.Port)
|
network, address := NetworkAddress(fallbackConfig.Host, fallbackConfig.Port)
|
||||||
@ -507,7 +507,7 @@ func (pgConn *PgConn) Close(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
pgConn.status = connStatusClosed
|
pgConn.status = connStatusClosed
|
||||||
|
|
||||||
defer close(pgConn.cleanupChan)
|
defer close(pgConn.cleanupDone)
|
||||||
defer pgConn.conn.Close()
|
defer pgConn.conn.Close()
|
||||||
|
|
||||||
if ctx != context.Background() {
|
if ctx != context.Background() {
|
||||||
@ -542,7 +542,7 @@ func (pgConn *PgConn) asyncClose() {
|
|||||||
pgConn.status = connStatusClosed
|
pgConn.status = connStatusClosed
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(pgConn.cleanupChan)
|
defer close(pgConn.cleanupDone)
|
||||||
defer pgConn.conn.Close()
|
defer pgConn.conn.Close()
|
||||||
|
|
||||||
deadline := time.Now().Add(time.Second * 15)
|
deadline := time.Now().Add(time.Second * 15)
|
||||||
@ -559,7 +559,7 @@ func (pgConn *PgConn) asyncClose() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CleanupChan returns a channel that will be closed after all underlying resources have been cleaned up. A closed
|
// CleanupDone returns a channel that will be closed after all underlying resources have been cleaned up. A closed
|
||||||
// connection is no longer usable, but underlying resources, in particular the net.Conn, may not have finished closing
|
// connection is no longer usable, but underlying resources, in particular the net.Conn, may not have finished closing
|
||||||
// yet. This is because certain errors such as a context cancellation require that the interrupted function call return
|
// yet. This is because certain errors such as a context cancellation require that the interrupted function call return
|
||||||
// immediately, but the error may also cause the connection to be closed. In these cases the underlying resources are
|
// immediately, but the error may also cause the connection to be closed. In these cases the underlying resources are
|
||||||
@ -567,13 +567,13 @@ func (pgConn *PgConn) asyncClose() {
|
|||||||
//
|
//
|
||||||
// This is only likely to be useful to connection pools. It gives them a way avoid establishing a new connection while
|
// This is only likely to be useful to connection pools. It gives them a way avoid establishing a new connection while
|
||||||
// an old connection is still being cleaned up and thereby exceeding the maximum pool size.
|
// an old connection is still being cleaned up and thereby exceeding the maximum pool size.
|
||||||
func (pgConn *PgConn) CleanupChan() chan (struct{}) {
|
func (pgConn *PgConn) CleanupDone() chan (struct{}) {
|
||||||
return pgConn.cleanupChan
|
return pgConn.cleanupDone
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsClosed reports if the connection has been closed.
|
// IsClosed reports if the connection has been closed.
|
||||||
//
|
//
|
||||||
// CleanupChan() can be used to determine if all cleanup has been completed.
|
// CleanupDone() can be used to determine if all cleanup has been completed.
|
||||||
func (pgConn *PgConn) IsClosed() bool {
|
func (pgConn *PgConn) IsClosed() bool {
|
||||||
return pgConn.status < connStatusIdle
|
return pgConn.status < connStatusIdle
|
||||||
}
|
}
|
||||||
@ -1605,7 +1605,7 @@ func Construct(hc *HijackedConn) (*PgConn, error) {
|
|||||||
status: connStatusIdle,
|
status: connStatusIdle,
|
||||||
|
|
||||||
wbuf: make([]byte, 0, wbufLen),
|
wbuf: make([]byte, 0, wbufLen),
|
||||||
cleanupChan: make(chan struct{}),
|
cleanupDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
pgConn.contextWatcher = ctxwatch.NewContextWatcher(
|
pgConn.contextWatcher = ctxwatch.NewContextWatcher(
|
||||||
|
@ -548,7 +548,7 @@ func TestConnExecContextCanceled(t *testing.T) {
|
|||||||
assert.True(t, pgconn.Timeout(err))
|
assert.True(t, pgconn.Timeout(err))
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -686,7 +686,7 @@ func TestConnExecParamsCanceled(t *testing.T) {
|
|||||||
|
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -835,7 +835,7 @@ func TestConnExecPreparedCanceled(t *testing.T) {
|
|||||||
assert.True(t, pgconn.Timeout(err))
|
assert.True(t, pgconn.Timeout(err))
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -1322,7 +1322,7 @@ func TestConnCopyToCanceled(t *testing.T) {
|
|||||||
|
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -1418,7 +1418,7 @@ func TestConnCopyFromCanceled(t *testing.T) {
|
|||||||
|
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -1673,7 +1673,7 @@ func TestConnContextCanceledCancelsRunningQueryOnServer(t *testing.T) {
|
|||||||
assert.True(t, pgconn.Timeout(err))
|
assert.True(t, pgconn.Timeout(err))
|
||||||
assert.True(t, pgConn.IsClosed())
|
assert.True(t, pgConn.IsClosed())
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
@ -1781,7 +1781,7 @@ func TestConnCloseWhileCancellableQueryInProgress(t *testing.T) {
|
|||||||
closeCtx, _ := context.WithCancel(context.Background())
|
closeCtx, _ := context.WithCancel(context.Background())
|
||||||
pgConn.Close(closeCtx)
|
pgConn.Close(closeCtx)
|
||||||
select {
|
select {
|
||||||
case <-pgConn.CleanupChan():
|
case <-pgConn.CleanupDone():
|
||||||
case <-time.After(5 * time.Second):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("Connection cleanup exceeded maximum time")
|
t.Fatal("Connection cleanup exceeded maximum time")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user