Do not yield to the next middleware before handleQuery is done

This commit is contained in:
Daniel García Aubert 2020-02-20 12:16:20 +01:00
parent ac8086a8e3
commit 932fd8ef55
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 () {