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

asyncore calls handle_write() on closed sockets when use_poll=True #48940

Closed
forest mannequin opened this issue Dec 18, 2008 · 2 comments
Closed

asyncore calls handle_write() on closed sockets when use_poll=True #48940

forest mannequin opened this issue Dec 18, 2008 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@forest
Copy link
Mannequin

forest mannequin commented Dec 18, 2008

BPO 4690
Nosy @giampaolo, @intgr
Files
  • pollwritefail.py: example code
  • 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 2010-08-04.09:58:34.179>
    created_at = <Date 2008-12-18.00:32:01.517>
    labels = ['type-bug', 'library']
    title = 'asyncore calls handle_write() on closed sockets when use_poll=True'
    updated_at = <Date 2010-08-04.09:58:34.177>
    user = 'https://bugs.python.org/forest'

    bugs.python.org fields:

    activity = <Date 2010-08-04.09:58:34.177>
    actor = 'giampaolo.rodola'
    assignee = 'giampaolo.rodola'
    closed = True
    closed_date = <Date 2010-08-04.09:58:34.179>
    closer = 'giampaolo.rodola'
    components = ['Library (Lib)']
    creation = <Date 2008-12-18.00:32:01.517>
    creator = 'forest'
    dependencies = []
    files = ['12390']
    hgrepos = []
    issue_num = 4690
    keywords = []
    message_count = 2.0
    messages = ['78003', '112780']
    nosy_count = 4.0
    nosy_names = ['forest', 'giampaolo.rodola', 'josiah.carlson', 'intgr']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = 'needs patch'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4690'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @forest
    Copy link
    Mannequin Author

    forest mannequin commented Dec 18, 2008

    With use_poll=True on linux, asyncore calls handle_write() after the
    socket has been closed.

    More specifically, it looks like asyncore dispatches handle_read() and
    handle_close() events between the writable() test and the corresponding
    handle_write() call. If handle_close() calls close(), as asyncore's
    default implementation does, the subsequent handle_write() will fail and
    generate an EBADF (bad file descriptor) exception. If handle_error()
    also calls close(), as asyncore's default implementation does, this will
    mean close() gets called twice on the same socket.

    I am attaching example code which demonstrates the problem on Linux
    2.6.24 using python 2.5.2, 2.5.3rc1, and 2.6. In one window, run
    pollwritefail.py. In another window, establish a TCP connection to port
    12345 and immediately close it without reading or writing. This can be
    done from within the python interactive interpreter like this:

      import socket
      s=socket.socket( socket.AF_INET, socket.SOCK_STREAM); s.connect(
        ('localhost', 12345)); s.close()

    The output from pollwritefail.py will look like this:

    writable() - asyncore asked if we have data to write
    handle_read() - asyncore asked us to read
    handle_close() - asyncore said the remote host closed connection
    close() - we are closing our end of the connection
    handle_write() - asyncore asked us to write
    handle_error() - asyncore exception: (9, 'Bad file descriptor')
    close() - we are closing our end of the connection

    IMHO, two things need fixing here:

    1. When writable() returns True, the next handler asyncore calls should
      be handle_write(). Calling other handlers in between risks invalidating
      the writable() return value.

    2. After close(), asyncore should not call handle_write(), even if
      writable() would return true.

    @forest forest mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Dec 18, 2008
    @giampaolo giampaolo self-assigned this Jul 9, 2010
    @giampaolo
    Copy link
    Contributor

    This problem must have been solved at some point because this is what I get now on Linux by using python 2.7:

    writable() - asyncore asked if we have data to write
    handle_read() - asyncore asked us to read
    handle_close() - asyncore said the remote host closed connection
    close() - we are closing our end of the connection
    handle_close() - asyncore said the remote host closed connection
    close() - we are closing our end of the connection

    Closing out as outdated.

    @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

    1 participant