From 7289e856d9aa358a6f2cf5f43727c314d6811a8a Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 4 Apr 2019 13:39:21 +0200 Subject: [PATCH] chore(xen-api/_sessionCall): dont use _interruptOnDisconnect --- packages/xen-api/src/index.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/xen-api/src/index.js b/packages/xen-api/src/index.js index 89775d2b3..612381b18 100644 --- a/packages/xen-api/src/index.js +++ b/packages/xen-api/src/index.js @@ -680,27 +680,30 @@ export class Xapi extends EventEmitter { ]) } - async _sessionCall(method, args, timeout) { + _sessionCallRetryOptions = { + tries: 2, + when: error => + this._status !== DISCONNECTED && error?.code === 'SESSION_INVALID', + onRetry: () => this._sessionOpen(), + } + _sessionCall(method, args, timeout) { if (method.startsWith('session.')) { - throw new Error('session.*() methods are disabled from this interface') + return Promise.reject( + new Error('session.*() methods are disabled from this interface') + ) } - const sessionId = this._sessionId - assert.notStrictEqual(sessionId, undefined) + return pRetry(() => { + const sessionId = this._sessionId + assert.notStrictEqual(sessionId, undefined) - const newArgs = [sessionId] - if (args !== undefined) { - newArgs.push.apply(newArgs, args) - } - - return pRetry( - () => this._interruptOnDisconnect(this._call(method, newArgs, timeout)), - { - tries: 2, - when: { code: 'SESSION_INVALID' }, - onRetry: () => this._sessionOpen(), + const newArgs = [sessionId] + if (args !== undefined) { + newArgs.push.apply(newArgs, args) } - ) + + return this._call(method, newArgs, timeout) + }, this._sessionCallRetryOptions) } // FIXME: (probably rare) race condition leading to unnecessary login when: