This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: socket.recv(OOB) raises exception on closed socket
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: facundobatista Nosy List: facundobatista, roysmith
Priority: normal Keywords:

Created on 2005-12-13 03:14 by roysmith, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg27058 - (view) Author: Roy Smith (roysmith) Date: 2005-12-13 03:14
frame:pyClient$ python
Python 2.4.1 (#1, Aug 16 2005, 20:11:22) 
[GCC 3.4.3] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
frame:pyClient$ uname -a
SunOS frame 5.8 Generic_108528-27 sun4u sparc

If you try to read out-of-band data on a closed socket, the recv() call 
raises socket.error, signaling "invalid argument".  This seems wrong.  
Doing a normal (in-band) recv() on a closed socket returns an empty 
string; trying to read OOB data should do the same thing.

At worst, it should raise a more specific error.  I'm guessing this 
exception is reflecting an errno of EBADF.  A more specific error would 
at least make it clear that it's the first argument to recv() which was 
bad, not the second.

frame:pyClient$ cat oob.py
#!/usr/bin/env python

import socket

s = socket.socket()
s.connect (("localhost", 13))  # 13 = daytime
print "==> ", `s.recv(1024)`
print "OOB: ", `s.recv (1024, socket.MSG_OOB)`

frame:pyClient$ ./oob.py
==>  'Mon Dec 12 22:00:29 2005\n\r'
OOB: 
Traceback (most recent call last):
  File "./oob.py", line 8, in ?
    print "OOB: ", `s.recv (1024, socket.MSG_OOB)`
socket.error: (22, 'Invalid argument')
frame:pyClient$ 
msg59601 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-01-09 14:24
Tried it on Linux, but the behaviour is the same on Py2.5.

It was already fixed in the trunk (it returns "", as in the inbound read).

Thanks for the report!
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42684
2008-01-09 14:24:10facundobatistasetstatus: open -> closed
resolution: out of date
messages: + msg59601
2005-12-13 03:14:44roysmithcreate