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 = null;
if (err) {
next(err);
}
if (req.profiler) {
req.profiler.sendStats();
}
@ -121,6 +117,12 @@ function handleQuery ({ stats } = {}) {
stats.increment('sqlapi.query.success');
}
}
if (err) {
next(err);
} else {
next();
}
});
} catch (err) {
next(err);

View File

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

View File

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