From 2c9f6424c34830b11cc793ca28786d5ad979d967 Mon Sep 17 00:00:00 2001 From: "Benoit A." Date: Thu, 12 Oct 2023 14:24:35 +0200 Subject: [PATCH] HD-3340 drain stream when receiving an error on a PUT --- lib/hdcontroller.js | 6 ++++-- src/hdcontroller.ts | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/hdcontroller.js b/lib/hdcontroller.js index a5fe6215..07590fc0 100644 --- a/lib/hdcontroller.js +++ b/lib/hdcontroller.js @@ -61,7 +61,7 @@ class HDProxydClient { const options = opts || {}; this.bootstrap = opts.bootstrap === undefined ? [['localhost', '18888']] : _parseBootstrapList(opts.bootstrap); - this.bootstrap = shuffle_1.shuffle(this.bootstrap); + this.bootstrap = (0, shuffle_1.shuffle)(this.bootstrap); this.path = '/store/'; this.setCurrentBootstrap(this.bootstrap[0]); this.httpAgent = new http.Agent({ keepAlive: true }); @@ -253,6 +253,9 @@ class HDProxydClient { put(stream, size, params, reqUids, callback) { const log = this.createLogger(reqUids); this._failover('POST', stream, size, '', 0, log, (err, response) => { + if (response) { + response.resume(); + } if (err || !response) { return callback(err); } @@ -260,7 +263,6 @@ class HDProxydClient { return callback(new HDProxydError('no key returned')); } const key = response.headers['scal-key']; - response.resume(); // drain the stream response.on('end', () => { return callback(undefined, key); }); diff --git a/src/hdcontroller.ts b/src/hdcontroller.ts index 853d64f9..cfc60145 100644 --- a/src/hdcontroller.ts +++ b/src/hdcontroller.ts @@ -16,7 +16,7 @@ export class HDProxydError extends Error { type HDProxydCallback = (error?: HDProxydError, res?: http.IncomingMessage) => void; -type HDProxydClientPutCallback = (error?: HDProxydError, key?: string) => void; +type HDProxydClientPutCallback = (error?: HDProxydError, key?: string) => void; type HDProxydClientGetCallback = (error?: HDProxydError, res?: Stream) => void; type HDProxydClientDeleteCallback = (error?: HDProxydError) => void; @@ -298,6 +298,9 @@ export class HDProxydClient { public put(stream: Stream, size: number, params: any, reqUids: string, callback: HDProxydClientPutCallback): void { const log = this.createLogger(reqUids); this._failover('POST', stream, size, '', 0, log, (err?: HDProxydError, response?: http.IncomingMessage) => { + if (response) { + response.resume(); + } if (err || !response) { return callback(err); } @@ -305,7 +308,6 @@ export class HDProxydClient { return callback(new HDProxydError('no key returned')); } const key = response.headers['scal-key'] as string; - response.resume(); // drain the stream response.on('end', () => { return callback(undefined, key); });