This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: HTTPSConnection does not close when call close() method
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dstanek, orsenthil, pitrou, tanakorn
Priority: normal Keywords: patch

Created on 2011-01-24 10:51 by tanakorn, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ssl.py.patch tanakorn, 2011-01-24 10:51 ssl.py patch for SSLSocket close method
zombiesocket.py tanakorn, 2011-01-24 12:47 test case file
Messages (7)
msg126919 - (view) Author: Tanakorn Leesatapornwongsa (tanakorn) Date: 2011-01-24 10:51
With this code on python 2.6, I found that HTTPSConnection does not close connection properly.

from httplib import HTTPSConnection

for i in range(1000):
  https = HTTPSConnection("google.com")
  https.connect()
  https.request("GET", "/")
  response = https.getresponse()
  response.close()
  https.close()
  print i

After searching python library, I guess that in ssl.py, implementation of close() method of SSLSocket is wrong.
socket.close(self) should not be called when self._makefile_refs < 1 but should be call when self._makefile_refs == 1, isn't it?
I modified the code, made the patch and attached it with this issue.
msg126922 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-01-24 11:59
Can you provide a test case which actually illustrates that zombie socket
connections present after the HTTPS Connection and Close?
I see the logic in your patch. But I don't see no left over unclosed
connections upon ssl.close either.
msg126923 - (view) Author: Tanakorn Leesatapornwongsa (tanakorn) Date: 2011-01-24 12:47
I ran this attached file on my FreeBSD. After it printed "loop finished", I ran command `sockstat | grep python` and it showed


korn     python     58627 3  tcp4   10.0.2.15:28858       64.233.183.99:443
korn     python     58627 4  tcp4   10.0.2.15:23579       64.233.183.147:443
korn     python     58627 5  tcp4   10.0.2.15:52398       64.233.183.106:443
korn     python     58627 6  tcp4   10.0.2.15:18764       64.233.183.105:443
korn     python     58627 7  tcp4   10.0.2.15:46159       64.233.183.104:443
korn     python     58627 8  tcp4   10.0.2.15:36906       64.233.183.103:443
korn     python     58627 9  tcp4   10.0.2.15:45537       64.233.183.99:443
korn     python     58627 10 tcp4   10.0.2.15:24578       64.233.183.103:443
korn     python     58627 11 tcp4   10.0.2.15:26374       64.233.183.147:443
korn     python     58627 12 tcp4   10.0.2.15:57399       64.233.183.106:443
korn     python     58627 13 tcp4   10.0.2.15:12670       64.233.183.105:443
korn     python     58627 14 tcp4   10.0.2.15:56306       64.233.183.104:443
korn     python     58627 15 tcp4   10.0.2.15:42741       64.233.183.103:443
korn     python     58627 16 tcp4   10.0.2.15:16112       64.233.183.99:443
korn     python     58627 17 tcp4   10.0.2.15:25839       64.233.183.147:443
korn     python     58627 18 tcp4   10.0.2.15:59310       64.233.183.106:443
korn     python     58627 19 tcp4   10.0.2.15:35349       64.233.183.105:443
korn     python     58627 20 tcp4   10.0.2.15:31881       64.233.183.104:443
korn     python     58627 21 tcp4   10.0.2.15:21328       64.233.183.103:443
korn     python     58627 22 tcp4   10.0.2.15:61880       64.233.183.99:443
korn     python     58627 23 tcp4   10.0.2.15:47151       64.233.183.147:443
korn     python     58627 24 tcp4   10.0.2.15:12796       64.233.183.106:443
korn     python     58627 25 tcp4   10.0.2.15:57142       64.233.183.105:443
korn     python     58627 26 tcp4   10.0.2.15:17930       64.233.183.104:443
korn     python     58627 27 tcp4   10.0.2.15:13166       64.233.183.103:443
korn     python     58627 28 tcp4   10.0.2.15:43557       64.233.183.99:443
korn     python     58627 29 tcp4   10.0.2.15:39800       64.233.183.147:443
korn     python     58627 30 tcp4   10.0.2.15:17364       64.233.183.106:443
korn     python     58627 31 tcp4   10.0.2.15:50822       64.233.183.105:443
korn     python     58627 32 tcp4   10.0.2.15:59156       64.233.183.104:443
korn     python     58627 33 tcp4   10.0.2.15:41756       64.233.183.103:443
korn     python     58627 34 tcp4   10.0.2.15:18008       64.233.183.99:443
korn     python     58627 35 tcp4   10.0.2.15:44461       64.233.183.147:443

This should not be happend because I call https.close() in every loop iteration. And after I killed this python process, `sockstat | grep python` did not show anything.

Is this test case that you want?
msg126924 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-01-24 12:56
Can you try with either 2.6.6 or 2.7.1?
msg126932 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-01-24 17:00
I think, we are facing a platform specific bug here. I had tried
similar program earlier and I tried your attached snippet with python
2.6.6 and release27-maint branch and I dont see the zombie sockets on
Ubuntu 10.10.
msg126933 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-01-24 17:02
Rather than labelling it a platform-specific issue, I'd like the OP to test with the latest bugfix releases (2.6.6 and 2.7.1). Some things have definitely been fixed recently.
msg126991 - (view) Author: Tanakorn Leesatapornwongsa (tanakorn) Date: 2011-01-25 07:07
I have tested it on python 2.7.1 already. It quite works.

Thank you.
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55202
2011-01-25 07:08:19tanakornsetstatus: open -> closed
nosy: orsenthil, pitrou, dstanek, tanakorn
resolution: fixed
2011-01-25 07:07:32tanakornsetnosy: orsenthil, pitrou, dstanek, tanakorn
messages: + msg126991
2011-01-24 17:02:08pitrousetnosy: orsenthil, pitrou, dstanek, tanakorn
messages: + msg126933
2011-01-24 17:00:07orsenthilsetnosy: orsenthil, pitrou, dstanek, tanakorn
messages: + msg126932
2011-01-24 15:37:37dstaneksetnosy: + dstanek
2011-01-24 12:56:22pitrousetnosy: + pitrou
messages: + msg126924
2011-01-24 12:47:28tanakornsetfiles: + zombiesocket.py

messages: + msg126923
2011-01-24 11:59:31orsenthilsetfiles: - unnamed
2011-01-24 11:59:04orsenthilsetfiles: + unnamed

messages: + msg126922
nosy: + orsenthil
2011-01-24 10:51:43tanakorncreate