platiumky / pymssql

Automatically exported from code.google.com/p/pymssql
GNU Lesser General Public License v2.1
0 stars 0 forks source link

connection doesn't close after going out of scope #88

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
With the following script:

########

import pymssql

def get_connection():
    return pymssql.connect(
        server='xxx',
        user='xxx',
        password='xxx',
        database='xxx',
    )

def run_dummy_query():
    conn = get_connection()
    cur = conn.cursor()
    cur.execute('SELECT 1')
    row = cur.fetchone()
    print row

def main():
    for i in range(10):
        run_dummy_query()

    raw_input('Now run netstat in another console.\n'
        'There should be 10 connections in TIME_WAIT.\n'
        'Instead, they are all in ESTABLISHED.\n'
        'Press any key to end the script...')

if __name__ == '__main__':
    main()

########

netstat shows 10 connections in ESTABLISHED instead of TIME_WAIT. Somehow the 
connections do not close themselves after going out of scope.

Tested with revision 005f1ac15065.

Original issue reported on code.google.com by sok...@gmail.com on 10 Apr 2012 at 2:16

GoogleCodeExporter commented 8 years ago
Thanks for the bug report! I think that the patch in 
https://code.google.com/p/pymssql/issues/detail?id=107 will probably fix this. 
I don't know if I or Randy will get a chance to review it in the near future, 
but I want to. If you feel comfortable testing out the patch and reporting back 
if it fixes this issue, that will help move things forward a bit. 

Original comment by msabr...@gmail.com on 10 Aug 2013 at 8:58

GoogleCodeExporter commented 8 years ago

Original comment by msabr...@gmail.com on 10 Aug 2013 at 8:59

GoogleCodeExporter commented 8 years ago

Original comment by msabr...@gmail.com on 10 Aug 2013 at 9:02

GoogleCodeExporter commented 8 years ago
The patch contained #107 is exactly to fix the issue you describe above. If you 
can test it that would be great!

Original comment by guillaum...@gmail.com on 11 Aug 2013 at 2:47

GoogleCodeExporter commented 8 years ago
The patch in #107 may or may not be needed. 

From a quick experiment last night, it appears that this patch might not be 
needed after this commit:

https://code.google.com/p/pymssql/source/detail?r=54554641cc7e487b9e8d5aa63b7085
bc31a5f060

The above commit makes it so that connections actually get closed and removed 
from connection_object_list when they are out of scope.

Can you test it out?

Original comment by msabr...@gmail.com on 14 Aug 2013 at 4:05

GoogleCodeExporter commented 8 years ago
One of my co-workers just tested that this is indeed fixed in 2.1.1. Thanks!

Original comment by guillaum...@gmail.com on 12 May 2015 at 6:25