From 2f65a86aa08a8c05de0f5d864994b560f528d364 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Mon, 23 Jan 2023 17:59:33 +0100 Subject: [PATCH] fix(xen-api/putResource): fix a number of issues - hide `VDI_IO_ERROR` when using content-length hack - avoid unhandled rejection in case upload fails --- CHANGELOG.unreleased.md | 1 + packages/xen-api/src/index.js | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index b5b2a457d..4fd88e2c7 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -30,5 +30,6 @@ - @xen-orchestra/backups patch +- xen-api patch diff --git a/packages/xen-api/src/index.js b/packages/xen-api/src/index.js index 2c40747b3..f329ad922 100644 --- a/packages/xen-api/src/index.js +++ b/packages/xen-api/src/index.js @@ -520,24 +520,34 @@ export class Xapi extends EventEmitter { ) if (pTaskResult !== undefined) { - pTaskResult = pTaskResult.catch(error => { - error.url = response.url - throw error - }) - } + if (useHack) { + // In case of the hack, ignore (but log) the very probably `VDI_IO_ERROR` because it is usually irrelevant + pTaskResult = pTaskResult.catch(error => { + console.warn(this._humanId, 'Xapi#putResource', pathname, error) + }) + } else { + pTaskResult = pTaskResult.catch(error => { + error.url = response.url + throw error + }) - if (!useHack) { - // consume the response - response.resume() - - return pTaskResult + // avoid unhandled rejection in case the upload fails + pTaskResult.catch(noop) + } } const { req } = response if (!req.finished) { await fromEvents(req, ['close', 'finish']) } - response.cancel() + + if (useHack) { + response.cancel() + } else { + // consume the response + response.resume() + } + return pTaskResult }