[Twisted-Python] Handling exceptions in twisted.internet.udp?
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Mon Feb 8 09:57:05 MST 2010
On 04:20 pm, bra at fsn.hu wrote:
>Hello,
>
>I have a code, which opens persistent (connected, see:
>http://twistedmatrix.com/documents/current/core/howto/udp.html#auto2)
>UDP connections, and sends and receives data on them.
>
>The problem is that occasionally I receive ICMP 13 (administratively
>prohibited) errors from the destinations, which triggers and exception
>and closes the UDP socket. I would like to keep that open, no matter
>what happens.
>On FreeBSD the exception comes during writing into the socket with
>transport.write, so this is an easy one.
This is probably a bug:
http://twistedmatrix.com/trac/ticket/2790
So you're right that you have to handle it in your app code (and that
it's easy to do so, fortunately). Hopefully someday this will no longer
be true.
>But on Linux it's a little bit harder, because there I get exception
>not
>during writing, but reading, which is handled here:
>http://twistedmatrix.com/trac/browser/tags/releases/twisted-9.0.0/twisted/internet/udp.py#L113
And this looks like another bug. :)
>[snip]
>"/usr/lib64/python2.6/site-packages/Twisted-9.0.0_r27775-py2.6-linux-
>x86_64.egg/twisted/internet/udp.py",
>line 109, in doRead
> data, addr = self.socket.recvfrom(self.maxPacketSize)
> socket.error: [Errno 113] No route to host
>
>I wonder what is the preferred way of achieving that the socket will be
>write()-able and kept open regardless what ICMP or other sending or
>receiving error occurs?
It seems like udp.py should be handling EHOSTUNREACH (and probably
several more errors that it also misses currently). There's already a
`connectionRefused` callback which could be invoked to handle these
cases.
This seems pretty related to another open ticket:
http://twistedmatrix.com/trac/ticket/3396
Aside from monkey-patching the doRead method, I don't see a way for an
application to handle this one.
Development has started on fixing each of these issues. The latter
seems to even have been reviewed and is now waiting for someone to
address the review feedback.
Jean-Paul
More information about the Twisted-Python
mailing list