Merge pull request #530 from CartoDB/copy-gunzip-exceptions

Handle gunzip/zlib errors
This commit is contained in:
Simon Martín 2018-08-13 11:15:40 +02:00 committed by GitHub
commit 911a9efe1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -3,7 +3,8 @@
## 2.2.1
Released 2018-mm-dd
Announcements:
Bug fixes:
* Errors from zlib while gunzipping (`/sql/copyfrom` compressed requests) are now handled correctly.
## 2.2.0

View File

@ -125,6 +125,11 @@ function handleCopyFrom (logger) {
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);
})
.on('data', data => {
metrics.addSize(data.length);

View File

@ -187,6 +187,28 @@ describe('copy-endpoints', function() {
});
});
it('should return an error when gzip headers are not correct', function(done) {
assert.response(server, {
url: "/api/v1/sql/copyfrom?" + querystring.stringify({
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
}),
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
headers: {
host: 'vizzuality.cartodb.com',
'content-encoding': 'gzip'
},
method: 'POST'
},{}, function(err, res) {
assert.ifError(err);
assert.deepEqual(
JSON.parse(res.body),
{
error:["Error while gunzipping: incorrect header check"]
}
);
done();
});
});
});