add timeout to postgres backup commands

Kill pg_dump/pg_restore after 30 minutes so a lock wait cannot hang a
backup or leave the server disconnected from its database during a
restore. A killed restore rolls back via --single-transaction.
This commit is contained in:
Kevin Gatera 2026-08-02 18:15:34 -04:00
parent 67de627a3f
commit adcd1bae96
No known key found for this signature in database
GPG key ID: F0D9F5932458CFB9
2 changed files with 3 additions and 0 deletions

View file

@ -657,6 +657,8 @@ class BackupManager {
const options = { const options = {
maxBuffer: 10 * 1024 * 1024, maxBuffer: 10 * 1024 * 1024,
// Kill after 30 mins (e.g. lock waits) - a killed restore rolls back via --single-transaction
timeout: 30 * 60 * 1000,
env: connection.env env: connection.env
} }
childProcess.execFile(command, [...args, ...connection.args], options, (error, stdout, stderr) => { childProcess.execFile(command, [...args, ...connection.args], options, (error, stdout, stderr) => {

View file

@ -76,6 +76,7 @@ describe('BackupManager', () => {
]) ])
expect(execFileStub.firstCall.args[1].join(' ')).to.not.include('secretpass') expect(execFileStub.firstCall.args[1].join(' ')).to.not.include('secretpass')
expect(execFileStub.firstCall.args[2].env.PGPASSWORD).to.equal('secretpass') expect(execFileStub.firstCall.args[2].env.PGPASSWORD).to.equal('secretpass')
expect(execFileStub.firstCall.args[2].timeout).to.be.a('number')
}) })
it('should restore Postgres dumps in one transaction and clean existing objects', async () => { it('should restore Postgres dumps in one transaction and clean existing objects', async () => {