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

Commit986e055

Browse files
committed
close sql.DB before creating another one
1 parent7bde3b2 commit986e055

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎coderd/database/dbtestutil/broker.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ func (b *Broker) init(t TBSubset) error {
126126
varpqErr*pq.Error
127127
ifxerrors.As(err,&pqErr)&&pqErr.Code=="3D000" {
128128
// database does not exist.
129-
err=b.createCoderTestingDB(t)
129+
ifcloseErr:=coderTestingDB.Close();closeErr!=nil {
130+
returnxerrors.Errorf("close postgres connection: %w",closeErr)
131+
}
132+
err=createCoderTestingDB(t)
130133
iferr!=nil {
131134
returnxerrors.Errorf("create coder testing db: %w",err)
132135
}
@@ -135,14 +138,15 @@ func (b *Broker) init(t TBSubset) error {
135138
returnxerrors.Errorf("open postgres connection: %w",err)
136139
}
137140
}elseiferr!=nil {
141+
_=coderTestingDB.Close()
138142
returnxerrors.Errorf("ping '%s' database: %w",CoderTestingDBName,err)
139143
}
140144
b.coderTestingDB=coderTestingDB
141145
b.uuid=uuid.New()
142146
returnnil
143147
}
144148

145-
func(b*Broker)createCoderTestingDB(tTBSubset)error {
149+
funccreateCoderTestingDB(tTBSubset)error {
146150
db,err:=sql.Open("postgres",defaultConnectionParams.DSN())
147151
iferr!=nil {
148152
returnxerrors.Errorf("open postgres connection: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp