classification
Title: socket's OOB data management is broken on OS X and FreeBSD
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: Ikinoki, giampaolo.rodola, gregory.p.smith, josiahcarlson, loewis
Priority: normal Keywords:

Created on 2008-07-04 01:51 by giampaolo.rodola, last changed 2008-07-06 19:39 by gregory.p.smith. This issue is now closed.

Messages (7)
msg69236 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-07-04 01:51
I've tried to run the code below on Windows XP and Linux Ubuntu and it
works as expected. Here is the output:

expt -> o
read -> fo

On FreeBSD 7.0 it raises the following exception:

expt -> o
read -> fo 
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.5/threading.py", line 460, in __bootstrap
    self.run()
  File "/usr/local/lib/python2.5/threading.py", line 440, in run
    self.__target(*self.__args, **self.__kwargs)
  File "_test2.py", line 13, in server
    data = conn.recv(1024, socket.MSG_OOB)
error: (22, 'Invalid argument')





--- code ---

import socket, select, threading, time, os

def server():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(('', 1024))
    s.listen(1)
    conn, addr = s.accept()
    conn.setblocking(0)
    while 1:
        r, w, e = select.select([conn], [conn], [conn], 0.01)
        if e:
            data = conn.recv(1024, socket.MSG_OOB)
            print "expt -> " + data
        if r:
            data = conn.recv(1024)
            print "read -> " + data


threading.Thread(target=server).start()
time.sleep(0.1)
s = socket.socket()
s.connect(('127.0.0.1', 1024))
s.sendall('foo', socket.MSG_OOB)

--- /code ---
msg69239 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-07-04 02:19
This bug should be strictly related with issue 3278:
http://bugs.python.org/issue3278
msg69244 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-07-04 05:48
Why do you think this is a bug in Python, and not in FreeBSD?
msg69262 - (view) Author: Andrew Azarov (Ikinoki) Date: 2008-07-04 18:44
tested:

Python 2.5.2 (r252:60911, Jun 24 2008, 16:40:26) 
[GCC 4.2.1 20070719  [FreeBSD]] on freebsd7

FreeBSD tomcat 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Sun Feb 24 19:59:52
UTC 2008     root@logan.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

expt -> o
read -> fo
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.5/threading.py", line 486, in
__bootstrap_inner
    self.run()
  File "/usr/local/lib/python2.5/threading.py", line 446, in run
    self.__target(*self.__args, **self.__kwargs)
  File "test.py", line 13, in server
    data = conn.recv(1024, socket.MSG_OOB)
error: (22, 'Invalid argument')

and:
Python 2.5 (r25:51908, Jun 25 2007, 16:00:15) 
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5

FreeBSD timcat 5.4-RELEASE FreeBSD 5.4-RELEASE #0: Sat Sep  9 03:32:05
MSD 2006     root@timcat:/usr/obj/usr/src/sys/SMP  i386

expt -> o
read -> fo
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.5/threading.py", line 460, in __bootstrap
    self.run()
  File "/usr/local/lib/python2.5/threading.py", line 440, in run
    self.__target(*self.__args, **self.__kwargs)
  File "test.py2", line 13, in server
    data = conn.recv(1024, socket.MSG_OOB)
error: (22, 'Invalid argument')

and:

Python 2.4.3 (#1, Jun 23 2006, 10:54:52) 
[GCC 2.95.4 20020320 [FreeBSD]] on freebsd4

FreeBSD comanchee-girl 4.9-RELEASE-CMN-1.1 FreeBSD 4.9-RELEASE-CMN-1.1
#4: Mon Apr 26 02:11:27 MSD 2004    
root@comanchee-girl:/usr/obj/usr/src/sys/CMN  i386

expt -> o
read -> fo
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python2.4/threading.py", line 442, in __bootstrap
    self.run()
  File "/usr/local/lib/python2.4/threading.py", line 422, in run
    self.__target(*self.__args, **self.__kwargs)
  File "test.py", line 13, in server
    data = conn.recv(1024, socket.MSG_OOB)
error: (22, 'Invalid argument')


All versions are stable and working in production. Except 7th version
the servers are loaded (la 0.2 to 3) with http/mysql/mail daemons.
Seems like a bug in python socket usage of freebsd for long time.
msg69346 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2008-07-06 18:17
I agree with Martin.  Why are you sure that this is a Python bug and not
a FreeBSD bug?  As per the documentation of OOB data, it's not supported
by all operating systems or TCP/IP stacks.
msg69348 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2008-07-06 18:28
Sorry, the first reply of Martin slipped under my radar.
In fact I wasn't sure whether this was related to Python or FreeBSD.
I've filed this same report on the FreeBSD bug tracker:
http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/125258
If you're sure this is not related to python please close it, otherwise
we could wait for someone of the FreeBSD team to reply and confirm that
it's FreeBSD related.
msg69354 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2008-07-06 19:39
not a python issue.  thanks for opening one with FreeBSD.
History
Date User Action Args
2008-07-06 19:39:14gregory.p.smithsetstatus: open -> closed
resolution: not a bug
messages: + msg69354
2008-07-06 18:28:35giampaolo.rodolasetmessages: + msg69348
2008-07-06 18:17:37josiahcarlsonsetnosy: + josiahcarlson
messages: + msg69346
2008-07-06 17:13:40gregory.p.smithsetpriority: normal
assignee: gregory.p.smith
title: socket's OOB data management is broken on FreeBSD -> socket's OOB data management is broken on OS X and FreeBSD
nosy: + gregory.p.smith
2008-07-04 18:44:24Ikinokisetnosy: + Ikinoki
messages: + msg69262
2008-07-04 05:48:08loewissetnosy: + loewis
messages: + msg69244
2008-07-04 02:19:21giampaolo.rodolasetmessages: + msg69239
2008-07-04 01:56:43giampaolo.rodolasettype: behavior
components: + Library (Lib)
2008-07-04 01:51:19giampaolo.rodolacreate