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

Commit 29add24

Browse files
committed
fix callbacks when connection is not open and log error instead of hanging
1 parent 5d6c1b0 commit 29add24

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

initializers/dataAccess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ exports.dataAccess = function (api, next) {
270270
api.log('Finish executing ' + f, 'debug');
271271
}
272272
}).execute();
273-
}
273+
} else cb("Connection closed unexpectedly");
274274
}
275275
], function (err, result) {
276276
if (err) {
@@ -340,7 +340,7 @@ exports.dataAccess = function (api, next) {
340340
api.log('Finish executing ' + f, 'debug');
341341
}
342342
}).execute();
343-
}
343+
} else cb("Connection closed unexpectedly");
344344
}
345345
], function (err, result) {
346346
if (err) {

initializers/transaction.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ var handleConnectionFailure = function (api, connection, actionTemplate, error,
3030
};
3131

3232
// if the action is transactional, end the transaction
33-
if (actionTemplate.transaction === "write") {
34-
if (connection.dbConnectionMap[databaseName].isConnected()) {
35-
connection.dbConnectionMap[databaseName].endTransaction(error, callback);
36-
}
33+
if (actionTemplate.transaction === "write" && connection.dbConnectionMap[databaseName].isConnected()) {
34+
connection.dbConnectionMap[databaseName].endTransaction(error, callback);
3735
} else {
3836
callback(error);
39-
// connection.dbConnectionMap[databaseName].disconnect();
40-
// connection.error = error;
41-
// next(connection, false);
4237
}
4338
});
4439
};
@@ -102,7 +97,6 @@ exports.transaction = function (api, next) {
10297
// Begin transaction
10398
dbConnectionMap[databaseName].beginTransaction(callback);
10499
} else {
105-
// next(connection, true);
106100
callback();
107101
}
108102
}
@@ -148,11 +142,9 @@ exports.transaction = function (api, next) {
148142
};
149143

150144
// if the action is transactional, end the transaction
151-
if (actionTemplate.transaction === "write") {
145+
if (actionTemplate.transaction === "write" && connection.dbConnectionMap[databaseName].isConnected()) {
152146
connection.dbConnectionMap[databaseName].endTransaction(connection.response.error, callback);
153147
} else {
154-
// connection.dbConnectionMap[databaseName].disconnect();
155-
// next(connection);
156148
callback();
157149
}
158150
});

0 commit comments

Comments
 (0)