[cx-oracle-users] cx_oracle does not close TCP/IP connections on close(); relies on Python garbage
Brought to you by:
atuining
From: Michael B. <mi...@zz...> - 2011-05-14 16:35:21
|
I'm assuming this is intentional behavior, as illustrated by the script below. Wondering what the rationale is for delaying the close of a connection until the object is garbage collected - in particular, this makes it difficult for applications that are attempting to manage the total number of TCP connections opened, where the actual connection object might still be referenced somewhere. Such an approach is even more problematic if and when cx_Oracle begins to be run on platforms such as Pypy where reference counting GC isn't used, as garbage collection can be delayed entirely for any amount of time. This is cx_Oracle 5.1, script is tested on Mac OSX as well as Fedora 14. The script creates one connection, closes it, illustrates what network connections are set up to port 1521. Then del is called, network connections are illustrated again. On both platforms, the one ESTABLISHED connection goes to TIME_WAIT only after "del c" is called. import os import cx_Oracle import time print "Version:", cx_Oracle.version c = cx_Oracle.connect( dsn='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SID=xe)))', password='tiger', user='scott', ) c.close() time.sleep(.01) print "-" * 20 os.system("netstat -nt | grep 1521") del c time.sleep(.01) print "-" * 20 os.system("netstat -nt | grep 1521") output on OSX: Version: 5.1 -------------------- tcp4 0 0 127.0.0.1.1521 127.0.0.1.60111 ESTABLISHED tcp4 0 0 127.0.0.1.60111 127.0.0.1.1521 ESTABLISHED -------------------- tcp4 0 0 127.0.0.1.1521 127.0.0.1.60111 CLOSE_WAIT tcp4 0 0 127.0.0.1.60111 127.0.0.1.1521 FIN_WAIT_2 output on Fedora 14 (this is the server where Oracle is running, so some 1521s are already present): Version: 5.1 -------------------- tcp 0 0 66.228.40.238:48786 66.228.40.238:1521 ESTABLISHED tcp 0 0 127.0.0.1:49302 127.0.0.1:1521 ESTABLISHED tcp 0 0 127.0.0.1:1521 127.0.0.1:49302 ESTABLISHED tcp 0 0 66.228.40.238:1521 66.228.40.238:48786 ESTABLISHED -------------------- tcp 0 0 66.228.40.238:48786 66.228.40.238:1521 ESTABLISHED tcp 0 0 127.0.0.1:49302 127.0.0.1:1521 TIME_WAIT tcp 0 0 66.228.40.238:1521 66.228.40.238:48786 ESTABLISHED |