Merge pull request #643 from CartoDB/middlewarify-query-controller

Do not yield to the next middleware before handleQuery is done
This commit is contained in:
Daniel G. Aubert 2020-02-20 17:12:27 +01:00 committed by GitHub
commit 273cbd7045
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 9 deletions

View File

@ -106,10 +106,6 @@ function handleQuery ({ stats } = {}) {
formatter.sendResponse(opts, (err) => { formatter.sendResponse(opts, (err) => {
formatter = null; formatter = null;
if (err) {
next(err);
}
if (req.profiler) { if (req.profiler) {
req.profiler.sendStats(); req.profiler.sendStats();
} }
@ -121,6 +117,12 @@ function handleQuery ({ stats } = {}) {
stats.increment('sqlapi.query.success'); stats.increment('sqlapi.query.success');
} }
} }
if (err) {
next(err);
} else {
next();
}
}); });
} catch (err) { } catch (err) {
next(err); next(err);

View File

@ -322,18 +322,30 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
if (that.beforeSink) { if (that.beforeSink) {
that.beforeSink(); that.beforeSink();
} }
that.istream.pipe(that.ostream); that.istream
.pipe(that.ostream)
.on('end', () => {
callback(); callback();
that.cb();
})
.on('error', (err) => {
callback();
that.cb(err);
});
}) })
.on('error', function (e) { .on('error', function (e) {
console.log("Can't send response: " + e); console.log("Can't send response: " + e);
that.ostream.end(); that.ostream.end();
that.cb(e);
callback();
})
.on('end', () => {
that.cb();
callback(); callback();
}); });
} else { } else {
callback(); callback();
} }
this.cb();
}; };
module.exports = OgrFormat; module.exports = OgrFormat;

View File

@ -27,6 +27,8 @@ TopoJsonFormat.prototype.handleQueryRow = function (row) {
}; };
TopoJsonFormat.prototype.handleQueryEnd = function () { TopoJsonFormat.prototype.handleQueryEnd = function () {
const that = this;
if (this.error) { if (this.error) {
this.callback(this.error); this.callback(this.error);
return; return;
@ -118,6 +120,7 @@ TopoJsonFormat.prototype.handleQueryEnd = function () {
} }
stream.write(buffer); stream.write(buffer);
stream.end(); stream.end();
that.callback();
topology = null; topology = null;
} }
} }
@ -125,8 +128,6 @@ TopoJsonFormat.prototype.handleQueryEnd = function () {
}); });
} }
sendResponse(); sendResponse();
this.callback();
}; };
TopoJsonFormat.prototype.cancel = function () { TopoJsonFormat.prototype.cancel = function () {