[issue7806] httplib.HTTPConnection.getresponse closes socket which destroys the response
report at bugs.python.org
Fri Feb 19 23:57:07 CET 2010
Jeremy Hylton <jeremy at alum.mit.edu> added the comment:
I don't think the HTTPConnection class was designed to work with
sockets that don't follow the Python socket API. If you want to use a
different socket, you should create some wrapper that emulates the
Python socket ref count behavior.
On Mon, Feb 1, 2010 at 5:23 PM, Robert Buchholz <report at bugs.python.org> wrote:
> Robert Buchholz <rbu at freitagsrunde.org> added the comment:
> An example cannot be constructed using the standard python socket class. As you point out, the response.will_close attribute is set correctly: The client is supposed to close to connect after completion of the request (as does the server). However, when the HTTPConnection object calls close() on the socket, reading the request is not completed -- the request object merely created a file-like object representing the socket.
> The reason why this is not an issue is that the Python socket library does reference counting to determine when to close a socket object. When the HTTPConnection calls close(), its own socket object is destroyed and unreferenced. However, the file-like object in the HTTPResponse still has a copy of the socket.
> In alternative socket implementations (like Paramiko SOCKS-proxied sockets), this poses a problem: When the socket user calls close(), they actually close the socket -- as the original socket API documentation describes:
> Close the socket. It cannot be used after this call.
> makefile([mode[, bufsize]]) -> file object
> Return a regular file object corresponding to the socket. The mode
> and bufsize arguments are as for the built-in open() function.
> Consequently, I do not consider this to be a bug in Paramiko and reported it for the httplib. I can present example code using a paramiko tunneled socket (client and server) if you like.
> Python tracker <report at bugs.python.org>
> Python-bugs-list mailing list
> Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/jeremy%40alum.mit.edu
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list