diff --git a/services/history-v1/storage/lib/backupBlob.mjs b/services/history-v1/storage/lib/backupBlob.mjs index e5a4fc8289..ecb5689eab 100644 --- a/services/history-v1/storage/lib/backupBlob.mjs +++ b/services/history-v1/storage/lib/backupBlob.mjs @@ -240,11 +240,13 @@ export async function backupBlob(historyId, blob, tmpPath, persistor) { // record that we backed it up already await storeBlobBackup(projectId, hash) recordBackupConclusion('failure', 'already_backed_up') + // Blob already backed up so report success return } - // eventually queue this for retry - for now this will be fixed by running the script recordBackupConclusion('failure') logger.warn({ error, projectId, hash }, 'Failed to upload blob to backup') + // Always throw an exception if the blob is not backed up + throw error } finally { logger.debug({ projectId, hash }, 'Ended blob backup') } diff --git a/services/history-v1/test/acceptance/js/storage/backupBlob.test.mjs b/services/history-v1/test/acceptance/js/storage/backupBlob.test.mjs index 8b9eb5640b..b94d23f49c 100644 --- a/services/history-v1/test/acceptance/js/storage/backupBlob.test.mjs +++ b/services/history-v1/test/acceptance/js/storage/backupBlob.test.mjs @@ -152,6 +152,40 @@ describe('backupBlob', function () { }) }) + describe('when uploadBlobToBackup fails', function () { + let blob + let historyId + let mockPersistor + let uploadError + + beforeEach(async function () { + blob = await makeBlobForFile(filePath) + historyId = 'abc123def456abc789def123' + uploadError = new Error('Upload failed') + + // Create a mock persistor that rejects on sendStream + mockPersistor = { + sendStream: async () => { + throw uploadError + }, + } + }) + + it('rethrows the error and does not record the blob as backed up', async function () { + await expect( + backupBlob(historyId, blob, filePath, mockPersistor) + ).to.be.rejectedWith('Upload failed') + + const record = await backedUpBlobs.findOne({ + _id: new ObjectId(historyId), + blobs: { + $elemMatch: { $eq: new Binary(Buffer.from(blob.getHash(), 'hex')) }, + }, + }) + expect(record).to.not.exist + }) + }) + const cases = [ { name: 'text file',