Do not pass error for emitting cancel events

This commit is contained in:
Daniel García Aubert 2019-05-16 15:07:26 +02:00
parent 62dc063677
commit 9b21b813be

View File

@ -127,33 +127,31 @@ function handleCopyFrom (logger) {
pgstream.emit('error', err); pgstream.emit('error', err);
}) })
.on('close', () => { .on('close', () => {
const err = new Error('Connection closed by client'); pgstream.emit('cancelQuery');
pgstream.emit('cancelQuery', err); pgstream.emit('error', new Error('Connection closed by client'));
pgstream.emit('error', err);
})
.pipe(isGzip ? zlib.createGunzip() : new PassThrough())
.on('error', err => {
err.message = `Error while gunzipping: ${err.message}`;
metrics.end(null, err);
pgstream.emit('error', err);
}) })
.pipe(decompress) .pipe(decompress)
.on('data', data => { .on('data', data => {
metrics.addSize(data.length); metrics.addSize(data.length);
if(metrics.size > dbRemainingQuota) { if(metrics.size > dbRemainingQuota) {
const quotaError = new Error('DB Quota exceeded'); pgstream.emit('cancelQuery');
pgstream.emit('cancelQuery', err); return pgstream.emit('error', new Error('DB Quota exceeded'));
pgstream.emit('error', quotaError);
} }
if((metrics.gzipSize || metrics.size) > COPY_FROM_MAX_POST_SIZE) { if((metrics.gzipSize || metrics.size) > COPY_FROM_MAX_POST_SIZE) {
const maxPostSizeError = new Error( pgstream.emit('cancelQuery');
return pgstream.emit('error', new Error(
`COPY FROM maximum POST size of ${COPY_FROM_MAX_POST_SIZE_PRETTY} exceeded` `COPY FROM maximum POST size of ${COPY_FROM_MAX_POST_SIZE_PRETTY} exceeded`
); ));
pgstream.emit('cancelQuery', err);
pgstream.emit('error', maxPostSizeError);
} }
}) })
.on('error', err => {
err.message = `Error while gunzipping: ${err.message}`;
metrics.end(null, err);
pgstream.emit('cancelQuery');
pgstream.emit('error', err);
})
.pipe(pgstream) .pipe(pgstream)
.on('error', err => { .on('error', err => {
metrics.end(null, err); metrics.end(null, err);