Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 18253f3

Browse files
committed
Merge pull request #455 from appirio-tech/firefighting
add logging and timeouts
2 parents 2a660f0 + 64e135a commit 18253f3

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

config/logger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports.default = {
1212
logger.transports.push(function (api, winston) {
1313
return new (winston.transports.Console)({
1414
colorize: true,
15-
level: 'info',
15+
level: 'debug',
1616
timestamp: api.utils.sqlDateTime,
1717
json: false
1818
});
@@ -31,7 +31,7 @@ exports.default = {
3131
logger.transports.push(function (api, winston) {
3232
return new (winston.transports.File)({
3333
filename: api.config.general.paths.log[0] + '/actionhero-worker.log',
34-
level: 'info',
34+
level: 'debug',
3535
colorize: true,
3636
timestamp: api.utils.sqlDateTime,
3737
json: false

initializers/dataAccess.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ exports.dataAccess = function (api, next) {
178178
var error, dbServerPrefix = api.config.tcConfig.databaseMapping[databaseName],
179179
user, password, hostname, server, port, settings;
180180
error = helper.checkDefined(dbServerPrefix, "database server prefix");
181+
182+
api.log('Creating a new db connection at dataAccess','debug');
181183
if (error) {
184+
api.log('Error : ' + error, 'error');
182185
throw error;
183186
}
184187

initializers/transaction.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
/*jslint unparam: true */
1010

11+
var CONN_TIMEOUT = process.env.CONN_TIMEOUT || 5000;
12+
var DISCONNECT_ON_CONN_TIMEOUT = process.env.DISCONNECT_ON_CONN_TIMEOUT !== "false" ? true : false;
13+
var DISCONN_TIMEOUT = process.env.DISCONN_TIMEOUT || 5000;
14+
1115
var handleConnectionFailure = function (api, connection, actionTemplate, error, next) {
1216
api.log("Close all opened connections", "debug");
1317
var connectionClosedCount = 0;
1418
actionTemplate.databases.forEach(function (databaseName) {
1519
var callback;
1620
callback = function (err, result) {
1721
connection.dbConnectionMap[databaseName].disconnect();
18-
api.log("Connection is closed", "debug");
22+
api.log("Connection is closed for " + databaseName, "debug");
1923
if (err) {
2024
connection.error = err;
2125
next(connection, false);
@@ -57,6 +61,15 @@ exports.transaction = function (api, next) {
5761
transactionPreProcessor = function (connection, actionTemplate, next) {
5862
if (actionTemplate.transaction === "read" || actionTemplate.transaction === "write") {
5963
var dbConnectionMap = {}, dbConnection, callback, connectionOpenedCount = 0;
64+
65+
var connectTimeout = function() {
66+
api.log("Timed out without obtaining all DB connections", "error");
67+
if (DISCONNECT_ON_CONN_TIMEOUT) {
68+
handleConnectionFailure(api, connection, actionTemplate, "Open Timeout", next);
69+
}
70+
}
71+
72+
var clearMe = setTimeout(connectTimeout, CONN_TIMEOUT);
6073

6174
actionTemplate.databases.forEach(function (databaseName) {
6275
dbConnection = api.dataAccess.createConnection(databaseName);
@@ -68,12 +81,14 @@ exports.transaction = function (api, next) {
6881
callback = function (err, result) {
6982
connection.dbConnectionMap = dbConnectionMap;
7083
if (err) {
84+
clearTimeout(clearMe);
7185
handleConnectionFailure(api, connection, actionTemplate, err, next);
7286
return;
7387
}
7488

7589
connectionOpenedCount += 1;
7690
if (connectionOpenedCount === actionTemplate.databases.length) {
91+
clearTimeout(clearMe);
7792
api.log("All connections are opened", "debug");
7893
next(connection, true);
7994
}
@@ -121,6 +136,14 @@ exports.transaction = function (api, next) {
121136
* @param {Function} next - The callback function
122137
*/
123138
transactionPostProcessor = function (connection, actionTemplate, toRender, next) {
139+
140+
var disconnectTimeout = function() {
141+
api.error("Timed out without closing all DB connections", "error");
142+
// I dont want to call next(connection); here because I want to allow the execution to to continue in case connection can be closed after timeout
143+
}
144+
145+
var clearMe = setTimeout(disconnectTimeout, DISCONN_TIMEOUT);
146+
124147
var connectionClosedCount = 0;
125148
if (connection.dbConnectionMap !== null && connection.dbConnectionMap !== undefined && actionTemplate.transaction !== null && actionTemplate.transaction !== undefined) {
126149
actionTemplate.databases.forEach(function (databaseName) {
@@ -129,13 +152,15 @@ exports.transaction = function (api, next) {
129152
connection.dbConnectionMap[databaseName].disconnect();
130153
api.log("Connection is closed", "debug");
131154
if (err) {
155+
clearTimeout(clearMe);
132156
connection.error = err;
133157
next(connection);
134158
return;
135159
}
136160

137161
connectionClosedCount += 1;
138162
if (connectionClosedCount === actionTemplate.databases.length) {
163+
clearTimeout(clearMe);
139164
api.log("All connections are closed", "debug");
140165
next(connection);
141166
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
"forums-wrapper": "git://github.com/cloudspokes/forums-wrapper.git#12b57be495c2e10431173522bc9eff60e0575959",
2828
"heapdump": "^0.3.6",
2929
"highlight.js": ">= 8.3.0",
30-
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git#46d1c91c3a8e164f888e88627b8da712e9ceb855",
30+
"informix-wrapper": "git://github.com/cloudspokes/informix-wrapper.git",
3131
"java": "0.3.x",
32-
"jsonwebtoken": "0.4.x",
32+
"jsonwebtoken": "5.0.5",
3333
"ldapjs": "0.7.x",
3434
"mime": "~1.2.11",
3535
"mkdirp": "0.3.x",

0 commit comments

Comments
 (0)