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

urllib hangs when closing connection #60474

Closed
danielugra mannequin opened this issue Oct 17, 2012 · 9 comments
Closed

urllib hangs when closing connection #60474

danielugra mannequin opened this issue Oct 17, 2012 · 9 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@danielugra
Copy link
Mannequin

danielugra mannequin commented Oct 17, 2012

BPO 16270
Nosy @orsenthil, @giampaolo, @bitdancer
PRs
  • gh-81403: Fix for CacheFTPHandler in urllib #13951
  • Files
  • urllib.patch
  • 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 = 'https://github.com/giampaolo'
    closed_at = <Date 2012-10-19.11:41:53.772>
    created_at = <Date 2012-10-17.21:38:49.669>
    labels = ['type-bug', 'library']
    title = 'urllib hangs when closing connection'
    updated_at = <Date 2019-06-10.23:44:24.970>
    user = 'https://bugs.python.org/danielugra'

    bugs.python.org fields:

    activity = <Date 2019-06-10.23:44:24.970>
    actor = 'danh'
    assignee = 'giampaolo.rodola'
    closed = True
    closed_date = <Date 2012-10-19.11:41:53.772>
    closer = 'giampaolo.rodola'
    components = ['Library (Lib)']
    creation = <Date 2012-10-17.21:38:49.669>
    creator = 'daniel.ugra'
    dependencies = []
    files = ['27606']
    hgrepos = []
    issue_num = 16270
    keywords = ['patch', '3.3regression']
    message_count = 9.0
    messages = ['173209', '173212', '173223', '173224', '173323', '173325', '173326', '265227', '286020']
    nosy_count = 5.0
    nosy_names = ['orsenthil', 'giampaolo.rodola', 'r.david.murray', 'daniel.ugra', 'python-dev']
    pr_nums = ['13951']
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16270'
    versions = ['Python 3.2', 'Python 3.3', 'Python 3.4']

    @danielugra
    Copy link
    Mannequin Author

    danielugra mannequin commented Oct 17, 2012

    With version 3.3 (64 bit on Arch Linux) Python now hangs when closing FTP connection on some sites:

    url = "ftp://ftp.fu-berlin.de/pub/misc/movies/database/ratings.list.gz"
    
    with urllib.request.urlopen( url ):
    	pass

    @danielugra danielugra mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 17, 2012
    @giampaolo
    Copy link
    Contributor

    I guess this is about urllib, not ftplib.

    @bitdancer
    Copy link
    Member

    Well, urllib calls ftplib for ftp urls, so it might be about ftplib. But in that case it would be better to have a reproducer that *just* uses ftplib.

    @giampaolo
    Copy link
    Contributor

    I can reproduce the issue on python 3.3.
    To have a clearer understanding on what's going on use:

    import urllib.request
    import ftplib
    ftplib.FTP.debugging = 4
    url = "ftp://ftp.fu-berlin.de/pub/misc/movies/database/ratings.list.gz"
    with urllib.request.urlopen(url):
        pass

    The problem appears to be endtransfer() erroneously calling ftp.voidresp() (it just shouldn't):
    http://hg.python.org/cpython/file/f6fcff683866/Lib/urllib/request.py#l2328
    Patch in attachment fixes the issue.

    @giampaolo giampaolo changed the title ftplib hangs when closing connection urllib hangs when closing connection Oct 18, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 19, 2012

    New changeset edeeb727df86 by Giampaolo Rodola' in branch 'default':
    Fix issue bpo-16270: urllib may hang when used for retrieving files via FTP by using a context manager.
    http://hg.python.org/cpython/rev/edeeb727df86

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 19, 2012

    New changeset 2e6bcbb0ff59 by Giampaolo Rodola' in branch '3.3':
    Fix issue bpo-16270: urllib may hang when used for retrieving files via FTP by using a context manager.
    http://hg.python.org/cpython/rev/2e6bcbb0ff59

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 19, 2012

    New changeset 7f0d9637a3ad by Giampaolo Rodola' in branch '3.2':
    Fix issue bpo-16270: urllib may hang when used for retrieving files via FTP by using a context manager.
    http://hg.python.org/cpython/rev/7f0d9637a3ad

    @giampaolo giampaolo self-assigned this Oct 19, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 10, 2016

    New changeset 44d02a5d59fb by Senthil Kumaran in branch '2.7':
    Closes bpo-26960.
    https://hg.python.org/cpython/rev/44d02a5d59fb

    @orsenthil
    Copy link
    Member

    The original problem here was retrieving files failed (hung) when it was tried via context-manager

    1. For e.g after "reverting" the changes, if you use the original file without the context manager, it will succeed.
    fobj = urllib.request.urlopen( url )

    That indicates the fix in changing something in endtransfer method was improper. I have given more information here: http://bugs.python.org/issue27973#msg286016

    The proper fix will be revert the endtransfer changes, but fix it in contextmanager scenario. Add test cases to cover all these scenarios.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants