Open bkkwok opened 6 years ago
Did you ever get a response for this?
No, although I'd imagine the only better way is for a specific error code to be given for this exception. However this will suffice.
Well, i have the same problem, and my solution is to validate the reserved connection each time. I use bluebird, so my example is promisified.
const JDBC = require('jdbc');
const Promise = require('bluebird');
Promise.promisifyAll([
require('jdbc/lib/pool'),
require('jdbc/lib/connection'),
require('jdbc/lib/statement'),
require('jdbc/lib/callablestatement'),
require('jdbc/lib/preparedstatement'),
require('jdbc/lib/resultset')
]);
...
let connObj;
while (!connObj) {
connObj = await db.reserveAsync();
if (!(await connObj.conn.isValidAsync(1))) {
await connObj.conn.closeAsync();
// don't return the closed conn to the _pool and don't leave it in _reserved, just remove
db._reserved = _.reject(db._reserved, ({uuid}) => uuid == connObj.uuid);
connObj = undefined;
}
}
Every other night, my company's JDE server restarts and the connection is lost. In order to re-establish the connection, I have to restart my node process when I wake up.
This is the error I receive:
This question has been answered in #105.
However, how would my code be able to tell the difference between this specific error and a different type of sql exception.
I don't want to re-establish the connection unless it is a
Communication link failure
. One way I can think of is to catch the error, check iferr.message.includes('Communication link failure')
, and then reconnect.I'm using expressJs
db.js
index.js
Would this be the recommended way?