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: http.client.HTTPConnection.send double send data
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Missing "return" in HTTPConnection.send()
View: 16658
Assigned To: Nosy List: orsenthil, sanyi, serhiy.storchaka
Priority: normal Keywords:

Created on 2013-01-09 10:28 by sanyi, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg179429 - (view) Author: Attila Gerendi (sanyi) Date: 2013-01-09 10:28
In http.client.HTTPConnection's send(data) method if data has attribute read after is handled correctly as file-like object and sent out successfully the code continues to what should be an else branch (~line 858) and tries to send out again the data. This is harmless in most situations but only by chance and also run's unnecessary code.

I propose either to use an else branch for the code after line 858 or simply instead break return at line 853.

Cheers,
Sanyi
msg181017 - (view) Author: Attila Gerendi (sanyi) Date: 2013-01-31 13:03
Renamed the report since it's unsafe for sure.

This problem was previously called: Avoid unnecessary and possibly unsafe code from http.client.HTTPConnection.send. 


Imagine that the data parameter from HTTPConnection it's a file like object but it's not iterable, maybe some custom data wrapper.

the if hasattr(data, "read"): True branch will correctly send out the response then unnecessary continue to:

try:
            self.sock.sendall(data)
        except TypeError:
            if isinstance(data, collections.Iterable):
                for d in data:
                    self.sock.sendall(d)
            else:
                raise TypeError("data should be a bytes-like object "
                                "or an iterable, got %r" % type(data))

and crash!
msg201458 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-27 13:43
Seems this bug was fixed in issue16658.
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61108
2013-10-27 13:43:41serhiy.storchakasetstatus: open -> closed

superseder: Missing "return" in HTTPConnection.send()
nosy: + serhiy.storchaka

messages: + msg201458
type: crash -> behavior
resolution: remind -> duplicate
stage: resolved
2013-01-31 13:03:23sanyisettype: performance -> crash
resolution: remind
messages: + msg181017
title: Avoid unnecessary and possibly unsafe code from http.client.HTTPConnection.send -> http.client.HTTPConnection.send double send data
2013-01-09 17:13:12orsenthilsetnosy: + orsenthil
2013-01-09 10:28:27sanyicreate