[New-bugs-announce] [issue4853] I/O operation on closed socket: improve the error message

STINNER Victor report at bugs.python.org
Tue Jan 6 01:31:03 CET 2009


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

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 #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.

----------
files: socket_error_closed.patch
keywords: patch
messages: 79217
nosy: haypo
severity: normal
status: open
title: I/O operation on closed socket: improve the error message
versions: Python 3.0
Added file: http://bugs.python.org/file12612/socket_error_closed.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4853>
_______________________________________


More information about the New-bugs-announce mailing list