[Twisted-Python] mishandling windows connect error

Andrew Dalke dalke at dalkescientific.com
Wed Jun 4 01:28:12 EDT 2003


That error report I made earlier this evening is not reproducible under
Linux.  It's only under MS Windows.

Here's some more information.  Twisted isn't reporting the correct
error message for when a TCP connection fails under MS Windows.

Here's the reproducible

E:\dalke>..\Python22\python.exe
Python 2.2.3c1 (#41, May 22 2003, 19:16:28) [MSC 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> from twisted.web.xmlrpc import Proxy
 >>> from twisted.internet import reactor
 >>> def printValue(value):
...   print value
...   reactor.stop()
...
 >>> proxy = Proxy("http://beatty.userland.com:34686")
 >>> proxy.callRemote('test.sumprod', 3, 5).addCallbacks(printValue, 
printValue)
<Deferred at 0xc38f40>
 >>> reactor.run()
[Failure instance: Traceback: twisted.internet.error.ConnectError, [160]
]
 >>>

Under Linux, this reports "Connection refused" as expected.

The ConnectError contains the value [160].  Looking at the stack trace, 
I found
it was created in tcp.py in BaseClient.doConnect where it says

         # on windows failed connects are reported on exception
         # list, not write or read list.
         if platform.getType() == "win32":
             r, w, e = select.select([], [], [self.fileno()], 0.0)
             if e:
                 self.failIfNotConnected(error.getConnectError(e))
                 return

If there is an error then 'e' will contain a list of size one, which is
the fileno.  Now look at the getConnectError definition in 
internet/error.py

def getConnectError(e):
     """Given a socket exception, return connection error."""
     try:
         number, string = e
     except ValueError:
         return ConnectError(string=e)

This will always give a ValueError (list of size 1 can't be assigned to
two terms) so it returns a ConnectError with the 'string' set to the
single element list.

And this is the '[160]' reported in the ConnectError of the failure,
which means it was on fileno 160.

I do not claim to be a network person.  It's all confusing to me.  I
tried commenting out that block, to see what the connect_ex does.
It returns a EWOULDBLOCK.  That's as far as I took it.

It feels to me like there's a bug around there someplace.

					Andrew
					dalke at dalkescientific.com





More information about the Twisted-Python mailing list