Compare commits

...

1 Commits

Author SHA1 Message Date
Alexandre Merle 092e82dc6e wip 2018-01-31 14:10:33 +01:00
1 changed files with 3 additions and 11 deletions

View File

@ -12,7 +12,7 @@ export default function retrieveData(locations, retrieveDataFn, response, log) {
};
response.once('close', () => {
log.debug('received close event before response end');
_destroyResponse();
responseDestroyed = true;
});
eachSeries(locations,
@ -38,18 +38,9 @@ export default function retrieveData(locations, retrieveDataFn, response, log) {
}
if (responseDestroyed) {
log.debug('response destroyed before readable could stream');
readable.emit('close');
readable.destroy();
return _next(responseErr);
}
// client closed the connection abruptly
response.once('close', () => {
log.debug('received close event before readable end');
if (!responseDestroyed) {
_destroyResponse();
}
readable.emit('close');
return _next(responseErr);
});
// readable stream successfully consumed
readable.on('end', () => {
log.debug('readable stream end reached');
@ -58,6 +49,7 @@ export default function retrieveData(locations, retrieveDataFn, response, log) {
// errors on server side with readable stream
readable.on('error', err => {
log.error('error piping data from source');
_destroyResponse();
return _next(err);
});
return readable.pipe(response, { end: false });