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: UnboundLocalError in socket._sendfile_use_sendfile
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-02-18 15:50 by berker.peksag, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
socket_unboundlocalerror.diff berker.peksag, 2016-02-18 15:50 review
issue26384_v2.diff berker.peksag, 2016-09-17 19:18 review
issue26384_v3.diff berker.peksag, 2016-09-17 20:00 review
Messages (5)
msg260464 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-02-18 15:50
I noticed this while working on issue 16915:

Traceback (most recent call last):
  ...
  File "/home/berker/projects/cpython/default/Lib/socket.py", line 262, in _sendfile_use_sendfile
    raise _GiveupOnSendfile(err)  # not a regular file
UnboundLocalError: local variable 'err' referenced before assignment

Here's a patch.
msg260806 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-02-24 14:46
This issue can be tested without moking os.fstat():

        class F:
            def fileno(self):
                return fd
        with socket.socket() as sock:
            fd = os.open(os.curdir, os.O_RDONLY)
            os.close(fd)
            self.assertRaises(socket._GiveupOnSendfile,
                              sock._sendfile_use_sendfile, F())

os.fstat() can raise not only OSError. It may be worth to test also with fd = 2**1000 and fd = None.
msg276822 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-09-17 19:18
Thanks, Serhiy. Here's an updated patch.
msg276828 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-17 20:01
LGTM.
msg276837 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-09-17 20:22
New changeset 78efbf499611 by Berker Peksag in branch '3.5':
Issue #26384: Fix UnboundLocalError in socket._sendfile_use_sendfile
https://hg.python.org/cpython/rev/78efbf499611

New changeset 2156aa4050c7 by Berker Peksag in branch '3.6':
Issue #26384: Merge from 3.5
https://hg.python.org/cpython/rev/2156aa4050c7

New changeset 0d440fda8604 by Berker Peksag in branch 'default':
Issue #26384: Merge from 3.6
https://hg.python.org/cpython/rev/0d440fda8604
History
Date User Action Args
2022-04-11 14:58:27adminsetgithub: 70572
2016-09-17 20:23:45berker.peksagsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-09-17 20:22:35python-devsetnosy: + python-dev
messages: + msg276837
2016-09-17 20:01:17serhiy.storchakasetmessages: + msg276828
2016-09-17 20:00:10berker.peksagsetfiles: + issue26384_v3.diff
2016-09-17 19:18:55berker.peksagsetfiles: + issue26384_v2.diff

messages: + msg276822
versions: + Python 3.7
2016-07-01 10:42:42berker.peksaglinkissue27433 superseder
2016-02-24 14:46:23serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg260806
2016-02-18 15:50:52berker.peksagcreate