chrysn / aiocoap

The Python CoAP library
Other
264 stars 119 forks source link

Error handling enhancements #319

Closed chrysn closed 11 months ago

chrysn commented 1 year ago

Requests to invalid addresses (127.0.0.0) or unroutable addresses (v6 on a system w/o a default route) currently manifest in requests being sent until retransmission timeout (rather than erring out fast).

Ideally requests to hosts w/ A and AAAA records should probably respond sensibly to unroutability errors, but at least this makes the error more visible and tangible.

chrysn commented 1 year ago

The current proposed mechanism for AI_ADDRCONFIG is only effective when the relevant interfaces have no IPv6 at all -- which is the case when it is disabled completely (eg. by the NetworkManager setting for the interface), but not when the router just doesn't provide a route.

This is being tracked upstream at https://sourceware.org/bugzilla/show_bug.cgi?id=12377.

The best workaround proposed in the discussion is that "it's so easy to ask the system if the address is actually routable" -- it may be easy on the command line, but a) it's still a lot to do in the code, and b) AIU that's not portable (at least on Linux ip r get goes through AF_NETIF).

chrysn commented 1 year ago

The best approach I can find right now is to do a connect() on an ephemeral socket each time names are resolved. It's not pretty, but should work across platforms.

One reason why this is weird is that it's one of udp6's main benefits that it can use a single socket for a huge number of peers. Still, this is only creating a single socket at a time, and only when an address needs to be resolved (typically, that is the first time a request is sent through a URI), so it's still nice.