summaryrefslogtreecommitdiff
path: root/vendor/github.com/jackc/pgconn
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2021-11-27 15:26:58 +0100
committerLibravatar GitHub <noreply@github.com>2021-11-27 15:26:58 +0100
commit182b4eea73881c611a0f519576aa6ad2aa6799c2 (patch)
tree230fac469690fcee8797b13585e739be148d4789 /vendor/github.com/jackc/pgconn
parentRequire confirmed email when checking oauth token (#332) (diff)
downloadgotosocial-182b4eea73881c611a0f519576aa6ad2aa6799c2.tar.xz
Update dependencies (#333)
Diffstat (limited to 'vendor/github.com/jackc/pgconn')
-rw-r--r--vendor/github.com/jackc/pgconn/CHANGELOG.md7
-rw-r--r--vendor/github.com/jackc/pgconn/internal/ctxwatch/context_watcher.go13
-rw-r--r--vendor/github.com/jackc/pgconn/pgconn.go25
-rw-r--r--vendor/github.com/jackc/pgconn/stmtcache/lru.go8
4 files changed, 28 insertions, 25 deletions
diff --git a/vendor/github.com/jackc/pgconn/CHANGELOG.md b/vendor/github.com/jackc/pgconn/CHANGELOG.md
index 45c02f1e9..63933a3a9 100644
--- a/vendor/github.com/jackc/pgconn/CHANGELOG.md
+++ b/vendor/github.com/jackc/pgconn/CHANGELOG.md
@@ -1,3 +1,10 @@
+# 1.10.1 (November 20, 2021)
+
+* Close without waiting for response (Kei Kamikawa)
+* Save waiting for network round-trip in CopyFrom (Rueian)
+* Fix concurrency issue with ContextWatcher
+* LRU.Get always checks context for cancellation / expiration (Georges Varouchas)
+
# 1.10.0 (July 24, 2021)
* net.Timeout errors are no longer returned when a query is canceled via context. A wrapped context error is returned.
diff --git a/vendor/github.com/jackc/pgconn/internal/ctxwatch/context_watcher.go b/vendor/github.com/jackc/pgconn/internal/ctxwatch/context_watcher.go
index 391f0b791..b39cb3ee5 100644
--- a/vendor/github.com/jackc/pgconn/internal/ctxwatch/context_watcher.go
+++ b/vendor/github.com/jackc/pgconn/internal/ctxwatch/context_watcher.go
@@ -2,6 +2,7 @@ package ctxwatch
import (
"context"
+ "sync"
)
// ContextWatcher watches a context and performs an action when the context is canceled. It can watch one context at a
@@ -10,8 +11,10 @@ type ContextWatcher struct {
onCancel func()
onUnwatchAfterCancel func()
unwatchChan chan struct{}
- watchInProgress bool
- onCancelWasCalled bool
+
+ lock sync.Mutex
+ watchInProgress bool
+ onCancelWasCalled bool
}
// NewContextWatcher returns a ContextWatcher. onCancel will be called when a watched context is canceled.
@@ -29,6 +32,9 @@ func NewContextWatcher(onCancel func(), onUnwatchAfterCancel func()) *ContextWat
// Watch starts watching ctx. If ctx is canceled then the onCancel function passed to NewContextWatcher will be called.
func (cw *ContextWatcher) Watch(ctx context.Context) {
+ cw.lock.Lock()
+ defer cw.lock.Unlock()
+
if cw.watchInProgress {
panic("Watch already in progress")
}
@@ -54,6 +60,9 @@ func (cw *ContextWatcher) Watch(ctx context.Context) {
// Unwatch stops watching the previously watched context. If the onCancel function passed to NewContextWatcher was
// called then onUnwatchAfterCancel will also be called.
func (cw *ContextWatcher) Unwatch() {
+ cw.lock.Lock()
+ defer cw.lock.Unlock()
+
if cw.watchInProgress {
cw.unwatchChan <- struct{}{}
if cw.onCancelWasCalled {
diff --git a/vendor/github.com/jackc/pgconn/pgconn.go b/vendor/github.com/jackc/pgconn/pgconn.go
index 43b13e43a..382ad33c0 100644
--- a/vendor/github.com/jackc/pgconn/pgconn.go
+++ b/vendor/github.com/jackc/pgconn/pgconn.go
@@ -578,7 +578,6 @@ func (pgConn *PgConn) Close(ctx context.Context) error {
//
// See https://github.com/jackc/pgx/issues/637
pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
- pgConn.conn.Read(make([]byte, 1))
return pgConn.conn.Close()
}
@@ -605,7 +604,6 @@ func (pgConn *PgConn) asyncClose() {
pgConn.conn.SetDeadline(deadline)
pgConn.conn.Write([]byte{'X', 0, 0, 0, 4})
- pgConn.conn.Read(make([]byte, 1))
}()
}
@@ -1187,27 +1185,6 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
return nil, &writeError{err: err, safeToRetry: n == 0}
}
- // Read until copy in response or error.
- var commandTag CommandTag
- var pgErr error
- pendingCopyInResponse := true
- for pendingCopyInResponse {
- msg, err := pgConn.receiveMessage()
- if err != nil {
- pgConn.asyncClose()
- return nil, preferContextOverNetTimeoutError(ctx, err)
- }
-
- switch msg := msg.(type) {
- case *pgproto3.CopyInResponse:
- pendingCopyInResponse = false
- case *pgproto3.ErrorResponse:
- pgErr = ErrorResponseToPgError(msg)
- case *pgproto3.ReadyForQuery:
- return commandTag, pgErr
- }
- }
-
// Send copy data
abortCopyChan := make(chan struct{})
copyErrChan := make(chan error, 1)
@@ -1246,6 +1223,7 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
}
}()
+ var pgErr error
var copyErr error
for copyErr == nil && pgErr == nil {
select {
@@ -1282,6 +1260,7 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
}
// Read results
+ var commandTag CommandTag
for {
msg, err := pgConn.receiveMessage()
if err != nil {
diff --git a/vendor/github.com/jackc/pgconn/stmtcache/lru.go b/vendor/github.com/jackc/pgconn/stmtcache/lru.go
index f58f2ac34..90fb76c2f 100644
--- a/vendor/github.com/jackc/pgconn/stmtcache/lru.go
+++ b/vendor/github.com/jackc/pgconn/stmtcache/lru.go
@@ -42,6 +42,14 @@ func NewLRU(conn *pgconn.PgConn, mode int, cap int) *LRU {
// Get returns the prepared statement description for sql preparing or describing the sql on the server as needed.
func (c *LRU) Get(ctx context.Context, sql string) (*pgconn.StatementDescription, error) {
+ if ctx != context.Background() {
+ select {
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ default:
+ }
+ }
+
// flush an outstanding bad statements
txStatus := c.conn.TxStatus()
if (txStatus == 'I' || txStatus == 'T') && len(c.stmtsToClear) > 0 {