Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: improve dump error output #3499

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2022
Merged
Changes from all 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
20 changes: 16 additions & 4 deletions coderd/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
"golang.org/x/xerrors"
Expand Down Expand Up @@ -123,27 +124,38 @@ func Open() (string, func(), error) {
}

pool.MaxWait = 120 * time.Second

// Record the error that occurs during the retry.
// The 'pool' pkg hardcodes a deadline error devoid
// of any useful context.
var retryErr error
err = pool.Retry(func() error {
db, err := sql.Open("postgres", dbURL)
if err != nil {
return xerrors.Errorf("open postgres: %w", err)
retryErr = xerrors.Errorf("open postgres: %w", err)
return retryErr
}
defer db.Close()

err = db.Ping()
if err != nil {
return xerrors.Errorf("ping postgres: %w", err)
retryErr = xerrors.Errorf("ping postgres: %w", err)
return retryErr
}

err = database.MigrateUp(db)
if err != nil {
return xerrors.Errorf("migrate db: %w", err)
retryErr = xerrors.Errorf("migrate db: %w", err)
// Only try to migrate once.
return backoff.Permanent(retryErr)
}

return nil
})
if err != nil {
return "", nil, err
return "", nil, retryErr
}

return dbURL, func() {
_ = pool.Purge(resource)
_ = os.RemoveAll(tempDir)
Expand Down