You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have validate function in Pool to check connection lost
myPool.prototype.validate = function(connection){
return connection["connected"]
}
var connected = pool.validate(conn) // true
// lost connect to db (lost network, db crashed ...)
// but connection doesn't update connected.
connected = pool.validate(conn) // true.
// so, how to know connection lost
The text was updated successfully, but these errors were encountered:
manhha1006
changed the title
Connection doesn't update.
Connection doesn't update status.
Mar 19, 2015
Internally we keep track of "connected" based on if a connection has been successfully opened or closed. It is really never updated asynchronously if a plug is pulled. See this related SO question:
My suggestion would be to actually do a simple query in the validate function to test if the server is still up:
myPool.prototype.validate=function(connection){try{connection.querySync("select 1+1 as test");}catch(error){//TODO: check the error is really because server failurereturnfalse;}returntrue;}
Note that that is blocking because of the call to querySync. If there is an asynchronous version of the validate function, I would do this:
myPool.prototype.validate=function(connection,cb){connection.querySync("select 1+1 as test",function(error,result){if(error){//TODO: check the error is really because server failurereturncb(false);}returncb(true);});}
This makes me realize that I am doing the same exact unhelpful thing in my odbc-pool module:
I have validate function in Pool to check connection lost
The text was updated successfully, but these errors were encountered: