From ede12b6732396107b2ac1a0117642af744c1c69d Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Wed, 21 Feb 2018 17:37:07 +0100 Subject: [PATCH] fix(xo-server): limit number of VM exports (#2671) Fixes #2669 --- packages/xo-server/package.json | 2 +- packages/xo-server/src/xapi/index.js | 7 ++----- yarn.lock | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/xo-server/package.json b/packages/xo-server/package.json index 66a792193..f32f1d066 100644 --- a/packages/xo-server/package.json +++ b/packages/xo-server/package.json @@ -78,7 +78,7 @@ "level": "^3.0.0", "level-party": "^3.0.4", "level-sublevel": "^6.6.1", - "limit-concurrency-decorator": "^0.3.0", + "limit-concurrency-decorator": "^0.4.0", "lodash": "^4.17.4", "make-error": "^1", "micromatch": "^3.1.4", diff --git a/packages/xo-server/src/xapi/index.js b/packages/xo-server/src/xapi/index.js index c0f4ca5a5..cb0272afb 100644 --- a/packages/xo-server/src/xapi/index.js +++ b/packages/xo-server/src/xapi/index.js @@ -9,6 +9,7 @@ import { cancellable, catchPlus as pCatch, defer, + fromEvent, ignoreErrors, } from 'promise-toolbox' import { PassThrough } from 'stream' @@ -84,9 +85,6 @@ export const VDI_FORMAT_RAW = 'raw' export const IPV4_CONFIG_MODES = ['None', 'DHCP', 'Static'] export const IPV6_CONFIG_MODES = ['None', 'DHCP', 'Static', 'Autoconf'] -// do not share the same limit for export and import, it could lead to deadlocks -const importLimit = concurrency(2) - // =================================================================== @mixin(mapToArray(mixins)) @@ -711,6 +709,7 @@ export default class Xapi extends XapiBase { } // Returns a stream to the exported VM. + @concurrency(2, stream => stream.then(stream => fromEvent(stream, 'end'))) async exportVm (vmId, { compress = true } = {}) { const vm = this.getObject(vmId) @@ -1227,7 +1226,6 @@ export default class Xapi extends XapiBase { ) } - @importLimit async _importVm (stream, sr, onVmCreation = undefined) { const taskRef = await this.createTask('VM import') const query = {} @@ -1256,7 +1254,6 @@ export default class Xapi extends XapiBase { return vmRef } - @importLimit @deferrable async _importOvaVm ( $defer, diff --git a/yarn.lock b/yarn.lock index 7e88b441e..09f55ae81 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7208,9 +7208,9 @@ liftoff@^2.5.0: rechoir "^0.6.2" resolve "^1.1.7" -limit-concurrency-decorator@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/limit-concurrency-decorator/-/limit-concurrency-decorator-0.3.0.tgz#f01dc6ece361ecc2169400847bad45d80727c79e" +limit-concurrency-decorator@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/limit-concurrency-decorator/-/limit-concurrency-decorator-0.4.0.tgz#d79c4e97b6ef547df2d905cc3acaabbae1bfeed6" livereload-js@^2.2.0: version "2.3.0"