From dbb4f340150faa67b0f1c099a4e6110c28369f27 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 3 Nov 2021 23:09:53 +0100 Subject: [PATCH] chore(xapi/VDI_destroy): decorate with retry.wrap() - more efficient than creating a function at each call - better logging --- @xen-orchestra/xapi/src/vdi.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/@xen-orchestra/xapi/src/vdi.js b/@xen-orchestra/xapi/src/vdi.js index b0460e2f6..565eb75fb 100644 --- a/@xen-orchestra/xapi/src/vdi.js +++ b/@xen-orchestra/xapi/src/vdi.js @@ -1,6 +1,7 @@ const CancelToken = require('promise-toolbox/CancelToken.js') const pCatch = require('promise-toolbox/catch.js') const pRetry = require('promise-toolbox/retry.js') +const { decorateWith } = require('@vates/decorate-with') const extractOpaqueRef = require('./_extractOpaqueRef.js') @@ -11,10 +12,13 @@ module.exports = class Vdi { return extractOpaqueRef(await this.callAsync('VDI.clone', vdiRef)) } + // work around a race condition in XCP-ng/XenServer where the disk is not fully unmounted yet + @decorateWith(pRetry.wrap, function () { + return this._vdiDestroyRetryWhenInUse + }) async destroy(vdiRef) { await pCatch.call( - // work around a race condition in XCP-ng/XenServer where the disk is not fully unmounted yet - pRetry(() => this.callAsync('VDI.destroy', vdiRef), this._vdiDestroyRetryWhenInUse), + this.callAsync('VDI.destroy', vdiRef), // if this VDI is not found, consider it destroyed { code: 'HANDLE_INVALID' }, noop