clueboy / pymssql_issues

0 stars 0 forks source link

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

Closed clueboy closed 11 years ago

clueboy commented 11 years ago

From sokann on April 09, 2012 19:16:18

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: http://code.google.com/p/pymssql/issues/detail?id=88

clueboy commented 11 years ago

From msabramo on August 10, 2013 13:58:10

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.

Status: Accepted
Labels: leak needstesting

clueboy commented 11 years ago

From msabramo on August 10, 2013 13:59:38

Owner: msabramo

clueboy commented 11 years ago

From msabramo on August 10, 2013 14:02:58

Cc: guillaume.pratte

clueboy commented 11 years ago

From guillaume.pratte on August 11, 2013 07:47:31

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

clueboy commented 11 years ago

From msabramo on August 13, 2013 21:05:13

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=54554641cc7e487b9e8d5aa63b7085bc31a5f060 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?

Status: Fixed