@@ -126,7 +126,10 @@ func (b *Broker) init(t TBSubset) error {
126
126
var pqErr * pq.Error
127
127
if xerrors .As (err ,& pqErr )&& pqErr .Code == "3D000" {
128
128
// database does not exist.
129
- err = b .createCoderTestingDB (t )
129
+ if closeErr := coderTestingDB .Close ();closeErr != nil {
130
+ return xerrors .Errorf ("close postgres connection: %w" ,closeErr )
131
+ }
132
+ err = createCoderTestingDB (t )
130
133
if err != nil {
131
134
return xerrors .Errorf ("create coder testing db: %w" ,err )
132
135
}
@@ -135,14 +138,15 @@ func (b *Broker) init(t TBSubset) error {
135
138
return xerrors .Errorf ("open postgres connection: %w" ,err )
136
139
}
137
140
}else if err != nil {
141
+ _ = coderTestingDB .Close ()
138
142
return xerrors .Errorf ("ping '%s' database: %w" ,CoderTestingDBName ,err )
139
143
}
140
144
b .coderTestingDB = coderTestingDB
141
145
b .uuid = uuid .New ()
142
146
return nil
143
147
}
144
148
145
- func ( b * Broker ) createCoderTestingDB (t TBSubset )error {
149
+ func createCoderTestingDB (t TBSubset )error {
146
150
db ,err := sql .Open ("postgres" ,defaultConnectionParams .DSN ())
147
151
if err != nil {
148
152
return xerrors .Errorf ("open postgres connection: %w" ,err )