diff --git a/NEWS.md b/NEWS.md index 0d09c866..dcf99733 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index 25bd85cb..f13c3647 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -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); diff --git a/test/acceptance/copy-endpoints.js b/test/acceptance/copy-endpoints.js index bf0e889a..b808faf4 100644 --- a/test/acceptance/copy-endpoints.js +++ b/test/acceptance/copy-endpoints.js @@ -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(); + }); + }); });