[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-12-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Sorry for the delay. I am not sure I understand your concern here:

 If the user reads the exact amount of bytes the server sent, read() on  the 
 socket will never have a chance to return '' and inform the user
 about the connection termination.

Certainly read(), called once again, would return ''? That's how I understand 
your unit test anyway.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-12-15 Thread Eran Rundstein

Eran Rundstein added the comment:

Hm, it's been a while and I'm no longer sure :(
You're right - since there is no length the user will have to call read() until 
he gets back ''. It's possible I forgot that assumption when speculating about 
this.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-12-15 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 2186f7b99c28 by Antoine Pitrou in branch '2.7':
Issue #16298: In HTTPResponse.read(), close the socket when there is no 
Content-Length and the incoming stream is finished.
http://hg.python.org/cpython/rev/2186f7b99c28

New changeset b47d342c449b by Antoine Pitrou in branch '3.2':
Issue #16298: In HTTPResponse.read(), close the socket when there is no 
Content-Length and the incoming stream is finished.
http://hg.python.org/cpython/rev/b47d342c449b

New changeset 59358f991c00 by Antoine Pitrou in branch '3.3':
Issue #16298: In HTTPResponse.read(), close the socket when there is no 
Content-Length and the incoming stream is finished.
http://hg.python.org/cpython/rev/59358f991c00

New changeset 5d6c2c7bc5d4 by Antoine Pitrou in branch 'default':
Issue #16298: In HTTPResponse.read(), close the socket when there is no 
Content-Length and the incoming stream is finished.
http://hg.python.org/cpython/rev/5d6c2c7bc5d4

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-12-15 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ok, the patch looked fine to me, so I've committed it to 2.7 and adapted it for 
3.x. Thank you!
By the way, it's probably easier to produce patches using Mercurial rather than 
using manual `diff`. You can have a look at the devguide for more information: 
http://docs.python.org/devguide/

--
resolution:  - fixed
stage: needs patch - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-12-15 Thread Eran Rundstein

Eran Rundstein added the comment:

My pleasure.
I had no idea about the Mercurial patch, this is the first time I have 
submitted a Python bug report :)
I'll have a look.

Thanks for merging the fix!

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-11-13 Thread Shivaram Lingamneni

Changes by Shivaram Lingamneni sling...@cs.stanford.edu:


--
nosy: +slingamn

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-11-06 Thread Eran Rundstein

Eran Rundstein added the comment:

Hello

I have attached a patch that includes a (slightly broken) fix and a test case. 
Note that there is currently an unresolved issue:
If the user reads the exact amount of bytes the server sent, read() on the 
socket will never have a chance to return '' and inform the user about the 
connection termination. This will also happen if the user reads more data than 
the server is sending. In that case, again, read() will not get called again so 
we will never know the socket is gone. One possible way to address this is 
perform the actual read() calls in a loop, attempting to read the exact amount 
the user specified. If we do this and the user attempts to read more bytes than 
the server sent, we will properly detect it. If, however, the user reads the 
exact length, then we still have a problem.

I am not sure what would be the correct way of solving this.

--
keywords: +patch
Added file: 
http://bugs.python.org/file27913/httplib-no-content-length-close-sock-fix.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-11-04 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 The patch is probably trivial - however I would still like some
 verification.
 Would it be correct to call self.close() when fp.read returns ''? In
 case self.length is not present, I don't see a way around this anyway.
 When it is present, and fp.read returns '', how should we go about
 that? We can either return less data, or raise an exception to
 indicate that the connection terminated prematurely.

It's probably better to return less data. No need to break user programs
when they download from a slightly misbehaved Web site.

The patch should include some kind of unit test, if possible. See
Lib/test/test_httplib.py.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-11-03 Thread Eran Rundstein

Eran Rundstein added the comment:

The patch is probably trivial - however I would still like some verification.
Would it be correct to call self.close() when fp.read returns ''? In case 
self.length is not present, I don't see a way around this anyway. When it is 
present, and fp.read returns '', how should we go about that? We can either 
return less data, or raise an exception to indicate that the connection 
terminated prematurely.

Thanks

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-10-28 Thread Andrew Svetlov

Andrew Svetlov added the comment:

Please publish patch for the issue.

--
nosy: +asvetlov

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-10-22 Thread Eran Rundstein

New submission from Eran Rundstein:

When calling HTTPResponse.read() on a response that is:
a. not chunked
b. contains no content-length header
the underlying socket (referenced by self.fp) will never get closed (through 
self.close())

The offending code is at the bottom of the read() function:
s = self.fp.read(amt)
if self.length is not None:
self.length -= len(s)
if not self.length:
self.close()
return s
As seen, if self.length is None, even when the server closes the connection 
(causing self.fp.read to return ''), the socket will not get closed.

btw, this may be the cause of Issue15633 (http://bugs.python.org/issue15633)

--
components: Library (Lib)
messages: 173505
nosy: eranrund
priority: normal
severity: normal
status: open
title: httplib.HTTPResponse.read could potentially leave the socket opened 
forever
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-10-22 Thread Piotr Dobrogost

Changes by Piotr Dobrogost p...@bugs.python.dobrogost.net:


--
nosy: +piotr.dobrogost

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16298] httplib.HTTPResponse.read could potentially leave the socket opened forever

2012-10-22 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +orsenthil, pitrou
stage:  - needs patch
versions: +Python 3.2, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16298
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com