New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot dispose of connection even if database session has been killed #67

Closed
zzzeek opened this Issue Aug 18, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@zzzeek
Copy link

zzzeek commented Aug 18, 2017

given a test as follows:

import cx_Oracle

conn = cx_Oracle.connect(
    user="scott",
    password="tiger",
    dsn=cx_Oracle.makedsn(
        "192.168.1.185", 1521, sid="xe",
    )
)

cursor = conn.cursor()
cursor.execute("select 1 from dual")

# run alter system kill session '<sid>, <session#>' here'
raw_input("stop the database, or kill the session, etc, press enter")

c2 = conn.cursor()

try:
    c2.execute("select 2 from data")
except cx_Oracle.DatabaseError as err:
    # cx_Oracle.DatabaseError: ORA-00028: your session has been killed
    print err

    # our session has been killed.  We have a dead socket in our application,
    # we need to clean it up unconditionally.

    # fails
    conn.close()

Given "Prevent closing the connection when there are any open statements or LOBs and add new error “DPI-1054: connection cannot be closed when open statements or LOBs exist”" in cx_Oracle 6.0, need to know the best practice in this situation. I understand the upstream Oracle OCI has added this but from a Python / scrpting language / humane POV this means I have to make sure all cursors are tracked at all times and also closed. this seems like something that could really easily be part of cx_Oracle, enabled by a flag on connect "auto-clean cursors", or if I could register event hooks to do this, it seems like there's a Subscription system now but it's not clear that it works for this.

@anthony-tuininga

This comment has been minimized.

Copy link
Member

anthony-tuininga commented Aug 18, 2017

The subscription system isn't meant for that. It is meant for database change and query change notification.

There is no need for the conn.close() in the general case. Python will clean it up automatically after all associated cursors (and other objects that were created from the connection) have been cleaned up. That said, internally fatal errors like "ORA-00028: your session has been killed" are tracked and I have added code to allow the connection to be closed in those cases. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment