tokio icon indicating copy to clipboard operation
tokio copied to clipboard

UdpFramed decode errors hide the source of the malformed packet

Open jasta opened this issue 3 years ago • 3 comments

When using UdpFramed, receiving data bundles the received item with the source SocketAddr but if there is a decode error, the error is delivered directly without the accompanying source SocketAddr. This means that developers cannot meaningfully identify malfunctioning peers even to just print debugging to figure out what's gone wrong.

I believe a reasonable solution is to simply change the Item type to:

type Item = Result<(C::Item, SocketAddr), (C::Error, Option<SocketAddr>)>;

The Option<SocketAddr> is needed as there is a case we get an I/O error in poll_recv_from and we don't have the address available from the underlying syscall.

This is a breaking API change of course, but I'm not quite sure if that's something tokio-util needs to be sensitive to.

jasta avatar Mar 29 '22 22:03 jasta

This seems fine

Noah-Kennedy avatar Mar 29 '22 23:03 Noah-Kennedy

Not sure when we will make a breaking release of tokio-util next, but seems fine to include next time we do so.

Darksonn avatar Mar 30 '22 11:03 Darksonn

I'll take a crack at a PR

jasta avatar May 04 '22 21:05 jasta