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:
commit
273cbd7045
@ -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);
|
||||
|
@ -322,18 +322,30 @@ ExportRequest.prototype.sendFile = function (err, filename, callback) {
|
||||
if (that.beforeSink) {
|
||||
that.beforeSink();
|
||||
}
|
||||
that.istream.pipe(that.ostream);
|
||||
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;
|
||||
|
@ -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 () {
|
||||
|
Loading…
Reference in New Issue
Block a user