diff --git a/lib/models/formats/ogr.js b/lib/models/formats/ogr.js index 556d9227..3daa2cd0 100644 --- a/lib/models/formats/ogr.js +++ b/lib/models/formats/ogr.js @@ -325,6 +325,7 @@ function ExportRequest (ostream, callback, beforeSink) { this.ostream = ostream; this.istream = null; this.canceled = false; + this.ended = false; var that = this; logger.info({ custom: true }, 'New export request'); @@ -373,17 +374,22 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) { .on('error', function (e) { logger.info({ custom: true }, 'Sending file: on error'); console.log("Can't send response: " + e); + that.ended = true; that.ostream.end(); that.cb(e); callback(); }) .on('end', () => { logger.info({ custom: true }, 'Sending file: on end'); + that.ended = true; that.cb(); callback(); }) .on('close', function() { logger.info({ custom: true }, 'Sending file: testing on close event'); + if (!that.ended) { + callback(); + } }); } else { logger.info({ custom: true }, 'It was cancelled (sending file)');