Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError in socket._sendfile_use_sendfile #70572

Closed
berkerpeksag opened this issue Feb 18, 2016 · 5 comments
Closed

UnboundLocalError in socket._sendfile_use_sendfile #70572

berkerpeksag opened this issue Feb 18, 2016 · 5 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@berkerpeksag
Copy link
Member

BPO 26384
Nosy @berkerpeksag, @serhiy-storchaka
Files
  • socket_unboundlocalerror.diff
  • issue26384_v2.diff
  • issue26384_v3.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2016-09-17.20:23:45.805>
    created_at = <Date 2016-02-18.15:50:52.431>
    labels = ['3.7', 'type-bug', 'library']
    title = 'UnboundLocalError in socket._sendfile_use_sendfile'
    updated_at = <Date 2016-09-17.20:23:45.804>
    user = 'https://github.com/berkerpeksag'

    bugs.python.org fields:

    activity = <Date 2016-09-17.20:23:45.804>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-09-17.20:23:45.805>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2016-02-18.15:50:52.431>
    creator = 'berker.peksag'
    dependencies = []
    files = ['41956', '44720', '44721']
    hgrepos = []
    issue_num = 26384
    keywords = ['patch']
    message_count = 5.0
    messages = ['260464', '260806', '276822', '276828', '276837']
    nosy_count = 3.0
    nosy_names = ['python-dev', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26384'
    versions = ['Python 3.5', 'Python 3.6', 'Python 3.7']

    @berkerpeksag
    Copy link
    Member Author

    I noticed this while working on bpo-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.

    @berkerpeksag berkerpeksag added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 18, 2016
    @serhiy-storchaka
    Copy link
    Member

    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.

    @berkerpeksag
    Copy link
    Member Author

    Thanks, Serhiy. Here's an updated patch.

    @berkerpeksag berkerpeksag added the 3.7 (EOL) end of life label Sep 17, 2016
    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 17, 2016

    New changeset 78efbf499611 by Berker Peksag in branch '3.5':
    Issue bpo-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 bpo-26384: Merge from 3.5
    https://hg.python.org/cpython/rev/2156aa4050c7

    New changeset 0d440fda8604 by Berker Peksag in branch 'default':
    Issue bpo-26384: Merge from 3.6
    https://hg.python.org/cpython/rev/0d440fda8604

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants