[Twisted-Python] socket error 22

Jean-Paul Calderone exarkun at divmod.com
Thu May 8 14:14:52 EDT 2008

On Tue, 06 May 2008 16:43:46 +0200, Werner Thie <wthie at thiengineering.ch> wrote:
>Hi all
>Running on twisted 2.5 OpenBSD I see the following traceback in the logs 
>every twenty minutes with up to 200 athena/LivePages connected:
>     Traceback (most recent call last):
>     --- <exception caught here> ---
>       File "/usr/local/lib/python2.5/site- 
>packages/twisted/internet/selectreactor.py", line 148, in _doReadOrWrite
>         why = getattr(selectable, method)()
>       File "/usr/local/lib/python2.5/site-packages/twisted/internet/tcp.py", 
>line 362, in doRead
>         return self.protocol.dataReceived(data)
>       File "/usr/local/lib/python2.5/site- 
>packages/twisted/protocols/basic.py", line 233, in dataReceived
>         why = self.lineReceived(line)
>       File "/usr/local/lib/python2.5/site-packages/twisted/web/http.py", 
>line 1069, in lineReceived
>         self.allContentReceived()
>       File "/usr/local/lib/python2.5/site-packages/twisted/web/http.py", 
>line 1110, in allContentReceived
>         req.requestReceived(command, path, version)
>       File "/usr/local/lib/python2.5/site-packages/twisted/web/http.py", 
>line 603, in requestReceived
>         self.host = self.channel.transport.getHost()
>       File "/usr/local/lib/python2.5/site-packages/twisted/internet/tcp.py", 
>line 672, in getHost
>         return address.IPv4Address('TCP', *(self.socket.getsockname() + 
>       File "<string>", line 1, in getsockname
>     socket.error: (22, 'Invalid argument')
>Changing reactors does not help, the error is very unspecific. Before I 
>start changing the source sprinkling it with log statements is there anybody 
>out there who has a cure or knows an explanation.

I wonder if OpenBSD gives back EINVAL for getsockname(2) when the peer has
done a shutdown of the socket.  Can you tell me what this program does?

    from socket import socket
    port = socket()
    port.bind(('', 0))
    client = socket()
    server, clientAddr = port.accept()
    print 'Before close', server.getsockname()
    print 'After close', server.getsockname()

If it finishes without error, try it with a time.sleep(5) before the final

Also, to re-iterate what I believe someone else already said in this thread,
the best way to have Twisted work on OpenBSD is for there to be an OpenBSD
buildslave.  It's easy to set up new buildslaves, the only requirements are
that the machine can make outgoing TCP connections to the master and that it
can run the Twisted test suite whenever there's a trunk change or someone
needs to test something on the platform.


More information about the Twisted-Python mailing list