wmjie / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

ibm-db module not resilient when DB2 server is restarted #137

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When I use sqlalchemy with ibm_db_sa dialect the sqlalchemy engine logic to 
re-cycle the connection pool in event of connection failure is not running 
because the the error is not recognized as a connection issue in the 
is_disconnect function under ibm_db_sa/ibm_db.py

To recreate:
1. Create a sqlalchemy engine with default connection pool params and working 
connection string. 
2. Execute a query you know works, verify still works
3. Now restart DB2 server
4. Try to excute the query again
5. You will see and exception and a rollback
6. Try running the query again, is still not working with same error

I would expect that first time the error occurs it will report this is a 
connection issue via is_disconnect() function so that sqlalchemy engine can 
refresh the connection pool. Second time you call the query it should work

Running ibm_db_sa-0.3.0 and SQLAlchemy-0.7.9 in a Ubuntu Precise x86-64

Here is the exception text:

ibm_db_dbi::OperationalError: SQLNumResultCols failed: [IBM][CLI Driver] 
SQL30081N  A communication error has been detected. Communication protocol 
being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where 
the error was detected: "127.0.0.1".  Communication function detecting the 
error: "recv".  Protocol specific error code(s): "*", "*", "0".  SQLSTATE=08001 
SQLCODE=-30081

If I make this change things work for me:

--- /usr/local/lib/python2.7/dist-packages/ibm_db_sa/old/ibm_db.py 2013-09-25 
22:18:02.421273243 +0000
+++ /usr/local/lib/python2.7/dist-packages/ibm_db_sa/ibm_db.py     2013-09-25 
21:31:09.557273243 +0000
@@ -101,7 +101,8 @@
                                              self.dbapi.OperationalError)):
             return 'Connection is not active' in str(ex) or \
                         'connection is no longer active' in str(ex) or \
-                        'Connection Resource cannot be found' in str(ex)
+                        'Connection Resource cannot be found' in str(ex) or \
+                       'SQLCODE=-30081' in str(ex)
         else:
             return False

Original issue reported on code.google.com by dperaz...@gmail.com on 25 Sep 2013 at 10:31

GoogleCodeExporter commented 9 years ago
Thanks for reporting this issue. I am able to reproduce this issue, and the fix 
is also correct. 

I will commit the changes required in google code git branch.

Original comment by rahul.pr...@in.ibm.com on 26 Sep 2013 at 11:46

GoogleCodeExporter commented 9 years ago

Original comment by rahul.pr...@in.ibm.com on 26 Sep 2013 at 11:46

GoogleCodeExporter commented 9 years ago
I have committed the changes in google code git branch at revision 3599797eb5c6 
.

Original comment by rahul.pr...@in.ibm.com on 26 Sep 2013 at 2:46

GoogleCodeExporter commented 9 years ago
The changes has been working fine with originator environment.

Original comment by rahul.pr...@in.ibm.com on 18 Nov 2013 at 6:29