node-odbc: "Communication link failure" state:"08S01" on a connection pool
Hi,
I have question about using connectionpool on my server.
I have defined a global variable named connection pool and when I want to query database I use it to query. that works fine but there is a problem that I think after a while being idle the server closes the connections and I face this error. "Communication link failure" state:"08S01" which the cause is explained here.
https://www.ibm.com/support/pages/odbc-client-connections-dropping-intermittently-error-communication-link-failure
Is there any way to workaround this problem in node-odbc?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 46 (5 by maintainers)
@markdirish We spoke at PowerUp about this issue and you invited me to tag you on it. The essence is that clients connecting from off the IBM i (Linux, Windows, etc.) time out and lose connection. People are currently coding around it to catch the error, disconnect and reconnect.
Any changes should just have to be done in JavaScript: Connections have a .connected property that calls SQLGetConnectAttr with the SQL_ATTR_CONNECTION_DEAD option. Returns true if SQL_ATTR_CONNECTION_DEAD returns false (since it makes much more sense for .connected to return true if its… connected). I imagine the code would just check:
Maybe the issue is here: https://github.com/markdirish/node-odbc/blob/69f49bd4703e569ef01693f4d9241bcdeffa5b00/lib/Pool.js#L253
I think an assumption is being made that the connection that’s being popped is a good connection, and perhaps
connection.connectedshould be checked on the popped connection. This will make sure the connection is good and if its not, to create a new connection.Unless the developer using the node-odbc pool is expected to try catch when they run
pool.queryand catch the connection error messageThen reinstantiate the pool. Which seems odd to me since I feel the pool should be gracefully handling dead connections without the developer needing to do anything.
Going back to the php_odbc.c source comparison. node-odbc doesn’t have a
It just has a function to check for a dead connection. It would be nice if node-odbc realized it had a dead connection and replaced it with a new connection.
Ah! sorry you’re right this code looks right. I’ll have to keep looking around to try and figure out why I’m getting
After the application is running for an entire day and request is made the next day.
These are the Db2 CLI docs, which is 90-95% the same as ODBC, but for some reason don’t seem to have this timeout…
The option can be found at the ODBC docs (which are annoyingly merged with SQL Server docs): https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlsetconnectattr-function?view=sql-server-ver15
@am2222 The ODBC timeout may work for the client side, but I don’t know if the ODBC connections in a connection pool will send keep-alives which means the connections to the DB2 server jobs for each connection can still die even though they may stay active on the i. If you’re running a remote server like I believe Liam is, I think the IBMi TCP keep-alive setting (on CHGTCPA) will be very important to set because of WAN/VPN connectivity and potential router timeout issue… I think the default IBMi keepalive may be 120 minutes. I changed mine to 2 and it resolved issues I was having with JDBC and other connections types like RDI so I’m guessing it will help for you as well.
I am getting this issue too and it’s urgent. Even with connectionTimeout as
0, after some idle time it seems to disconnect the connections. I went ahead and built node-odbc withDEBUGmode so we could see the log. You can also see a log of thepoolobject before the debug output.There is a long pause here before this error comes out: