Unpipe streams when error

This commit is contained in:
Daniel García Aubert 2019-05-16 17:24:21 +02:00
parent 9b21b813be
commit 17de6e8d4f

View File

@ -112,8 +112,8 @@ function handleCopyFrom (logger) {
const COPY_FROM_MAX_POST_SIZE_PRETTY = global.settings.copy_from_max_post_size_pretty || '2 GB';
const streamCopy = new StreamCopy(sql, userDbParams, logger);
const metrics = new StreamCopyMetrics(logger, 'copyfrom', sql, user, isGzip);
const decompress = isGzip ? zlib.createGunzip() : new PassThrough();
const metrics = new StreamCopyMetrics(logger, 'copyfrom', sql, user, isGzip);
streamCopy.getPGStream(StreamCopy.ACTION_FROM, (err, pgstream) => {
if (err) {
@ -155,7 +155,8 @@ function handleCopyFrom (logger) {
.pipe(pgstream)
.on('error', err => {
metrics.end(null, err);
req.unpipe(pgstream);
req.unpipe(decompress);
decompress.unpipe(pgstream);
return next(err);
})
.on('end', () => {