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

Commit301727d

Browse files
authored
chore: improve dump error output (coder#3499)
* chore: improve dump error output- Properly report the error that occurs during the DB connection retry loop.- Fail fatally if migration is unsuccessful.
1 parent8cf8211 commit301727d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

‎coderd/database/postgres/postgres.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010
"time"
1111

12+
"github.com/cenkalti/backoff/v4"
1213
"github.com/ory/dockertest/v3"
1314
"github.com/ory/dockertest/v3/docker"
1415
"golang.org/x/xerrors"
@@ -123,27 +124,38 @@ func Open() (string, func(), error) {
123124
}
124125

125126
pool.MaxWait=120*time.Second
127+
128+
// Record the error that occurs during the retry.
129+
// The 'pool' pkg hardcodes a deadline error devoid
130+
// of any useful context.
131+
varretryErrerror
126132
err=pool.Retry(func()error {
127133
db,err:=sql.Open("postgres",dbURL)
128134
iferr!=nil {
129-
returnxerrors.Errorf("open postgres: %w",err)
135+
retryErr=xerrors.Errorf("open postgres: %w",err)
136+
returnretryErr
130137
}
131138
deferdb.Close()
132139

133140
err=db.Ping()
134141
iferr!=nil {
135-
returnxerrors.Errorf("ping postgres: %w",err)
142+
retryErr=xerrors.Errorf("ping postgres: %w",err)
143+
returnretryErr
136144
}
145+
137146
err=database.MigrateUp(db)
138147
iferr!=nil {
139-
returnxerrors.Errorf("migrate db: %w",err)
148+
retryErr=xerrors.Errorf("migrate db: %w",err)
149+
// Only try to migrate once.
150+
returnbackoff.Permanent(retryErr)
140151
}
141152

142153
returnnil
143154
})
144155
iferr!=nil {
145-
return"",nil,err
156+
return"",nil,retryErr
146157
}
158+
147159
returndbURL,func() {
148160
_=pool.Purge(resource)
149161
_=os.RemoveAll(tempDir)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp