Skip to content

Commit

Permalink
HD-3340 drain stream when receiving an error on a PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-a committed Oct 12, 2023
1 parent c952990 commit 2c9f642
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/hdcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -253,14 +253,16 @@ 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);
}
if (!response.headers['scal-key']) {
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);
});
Expand Down
6 changes: 4 additions & 2 deletions src/hdcontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -298,14 +298,16 @@ 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);
}
if (!response.headers['scal-key']) {
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);
});
Expand Down

0 comments on commit 2c9f642

Please sign in to comment.