Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server close before flush #5935

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {WriteBatcher, ReadBatcher, InsertBatcher} = require('./parts/data/batcher
const pack = require('../package.json');
const versionInfo = require('../frontend/express/version.info.js');
const moment = require("moment");
let server;

var t = ["countly:", "api"];
common.processRequest = processRequest;
Expand Down Expand Up @@ -151,14 +152,20 @@ plugins.connectToAllDatabases().then(function() {
*/
async function storeBatchedData(code) {
try {
if (server && typeof server.close === "function") {
console.log("Closing server");
await server.close();
}
await common.writeBatcher.flushAll();
await common.insertBatcher.flushAll();
console.log("Successfully stored batch state");
}
catch (ex) {
console.log("Could not store batch state", ex);
}
process.exit(typeof code === "number" ? code : 1);
setTimeout(() => {
process.exit(typeof code === "number" ? code : 1);
}, 0);
}

/**
Expand Down Expand Up @@ -357,7 +364,7 @@ plugins.connectToAllDatabases().then(function() {

plugins.dispatch("/worker", {common: common});

http.Server((req, res) => {
server = http.Server((req, res) => {
const params = {
qstring: {},
res: res,
Expand Down Expand Up @@ -437,7 +444,8 @@ plugins.connectToAllDatabases().then(function() {
else {
common.returnMessage(params, 405, "Method not allowed");
}
}).listen(common.config.api.port, common.config.api.host || '').timeout = common.config.api.timeout || 120000;
});
server.listen(common.config.api.port, common.config.api.host || '').timeout = common.config.api.timeout || 120000;

plugins.loadConfigs(common.db);
}
Expand Down
Loading