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

I/O operation on closed socket: improve the error message #49103

Closed
vstinner opened this issue Jan 6, 2009 · 2 comments
Closed

I/O operation on closed socket: improve the error message #49103

vstinner opened this issue Jan 6, 2009 · 2 comments

Comments

@vstinner
Copy link
Member

vstinner commented Jan 6, 2009

BPO 4853
Nosy @vstinner
Files
  • socket_error_closed.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 = None
    closed_at = <Date 2009-12-11.11:42:38.342>
    created_at = <Date 2009-01-06.00:31:02.599>
    labels = []
    title = 'I/O operation on closed socket: improve the error message'
    updated_at = <Date 2009-12-11.11:42:38.340>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2009-12-11.11:42:38.340>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-12-11.11:42:38.342>
    closer = 'vstinner'
    components = []
    creation = <Date 2009-01-06.00:31:02.599>
    creator = 'vstinner'
    dependencies = []
    files = ['12612']
    hgrepos = []
    issue_num = 4853
    keywords = ['patch']
    message_count = 2.0
    messages = ['79217', '96246']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue4853'
    versions = ['Python 3.0']

    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 6, 2009

    I don't like the current behaviour of Python on closed socket:

    >>> import socket
    >>> s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    >>> s.close()
    >>> s.fileno()
    -1
    >>> s.getsockname()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    socket.error: [Errno 9] Bad file descriptor

    Some operations are still allowed whereas the other raise an ugly
    error message. Most (or all) operation on a closed socket should be
    blocked by a socket.error.

    My patch raises a socket.error("I/O operation on closed socket") for
    most operations except:

    • close(): it call be called twice (or more) (keep current behaviour)
    • gettimeout(): should we raise an error?
    • setblocking(), settimeout(): should we raise an error? Maybe yes
      for setter but no for getter which would be inconsistent with
      getpeername()...

    The io library already has this behaviour: read(), write(), flush(),
    etc. are blocked by a ValueError("I/O operation on closed file") (see
    IOBase._check_closed in the io library).

    Issue bpo-4791 changes the behaviour of closed SocketIO object: fileno()
    method raise a socket.error if it's closed even if the socket is still
    open.

    @vstinner
    Copy link
    Member Author

    Well, this issue is not really important. The current behaviour is already
    correct (raising an error if the file is closed).

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant