Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli): fix flakes related to context cancellation when establishing pg connections#18246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugodutka merged 1 commit intomainfromhugodutka/pg-cancellation-flakes
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletionscli/clitest/clitest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -168,6 +168,12 @@ func StartWithAssert(t *testing.T, inv *serpent.Invocation, assertCallback func(
switch {
case errors.Is(err, context.Canceled):
return
case err != nil && strings.Contains(err.Error(), "driver: bad connection"):
// When we cancel the context on a query that's being executed within
// a transaction, sometimes, instead of a context.Canceled error we get
// a "driver: bad connection" error.
// https://github.com/lib/pq/issues/1137
return
default:
assert.NoError(t, err)
}
Expand Down
5 changes: 4 additions & 1 deletioncli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2359,6 +2359,10 @@ func ConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
if err != nil {
return nil, xerrors.Errorf("get postgres version: %w", err)
}
defer version.Close()
if version.Err() != nil {
return nil, xerrors.Errorf("version select: %w", version.Err())
}
if !version.Next() {
return nil, xerrors.Errorf("no rows returned for version select")
}
Expand All@@ -2367,7 +2371,6 @@ func ConnectToPostgres(ctx context.Context, logger slog.Logger, driver string, d
if err != nil {
return nil, xerrors.Errorf("scan version: %w", err)
}
_ = version.Close()

if versionNum < 130000 {
return nil, xerrors.Errorf("PostgreSQL version must be v13.0.0 or higher! Got: %d", versionNum)
Expand Down
15 changes: 7 additions & 8 deletionscoderd/database/pubsub/pubsub.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -552,15 +552,14 @@ func (p *PGPubsub) startListener(ctx context.Context, connectURL string) error {
sentErrCh = true
}),
}
select {
case err = <-errCh:
if err != nil {
_ = p.pgListener.Close()
return xerrors.Errorf("create pq listener: %w", err)
}
case <-ctx.Done():
// We don't respect context cancellation here. There's a bug in the pq library
// where if you close the listener before or while the connection is being
// established, the connection will be established anyway, and will not be
// closed.
// https://github.com/lib/pq/issues/1192
if err := <-errCh; err != nil {
_ = p.pgListener.Close()
returnctx.Err()
returnxerrors.Errorf("create pq listener: %w", err)
}
return nil
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp