fix(schema): Database connection not cleanly closed
This commit introduces closing the Schema Manager's underlying driver connection. We were only releasing the shared lock but not actually cleaning up the db connection and relied on the fact that the process would exit to do that for us.
This commit is contained in:
1 parent
8e969787f9
commit
621f8a9ff2
3 files changed
+33
-17
No files matched your search
@@ -251,6 +251,11 @@ func (p *Postgres) Run(ctx context.Context, migration io.Reader, version int, ed
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close closes the underlying Postgres database connection.
|
||||
func (p *Postgres) Close() error {
|
||||
return p.conn.Close()
|
||||
}
|
||||
|
||||
var errOldMigrationTable = stderrors.New("old schema migration table")
|
||||
|
||||
func (p *Postgres) schemaInitialized(ctx context.Context) (bool, error) {
|
||||
|
||||
@@ -22,6 +22,7 @@ type driver interface {
|
||||
Lock(context.Context) error
|
||||
Unlock(context.Context) error
|
||||
UnlockShared(context.Context) error
|
||||
Close() error
|
||||
// StartRun begins a transaction internal to the driver.
|
||||
StartRun(context.Context) error
|
||||
// CommitRun commits a transaction, if there is an error it should rollback the transaction.
|
||||
@@ -123,6 +124,18 @@ func (b *Manager) CurrentState(ctx context.Context) (*State, error) {
|
||||
return &dbS, nil
|
||||
}
|
||||
|
||||
// Close unlocks the database shared lock and closes the underlying
|
||||
// database connection afterwards.
|
||||
func (b *Manager) Close(ctx context.Context) error {
|
||||
const op = "schema.(Manager).Close"
|
||||
err := b.SharedUnlock(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(ctx, err, op)
|
||||
}
|
||||
|
||||
return b.driver.Close()
|
||||
}
|
||||
|
||||
// SharedLock attempts to obtain a shared lock on the database. This can fail
|
||||
// if an exclusive lock is already held. If the lock can't be obtained an
|
||||
// error is returned.
|
||||
|
||||
Reference in new issue
Block a user