The missing UDP packets

Alexander Petrovsky askjuise@REDACTED
Fri Feb 7 14:50:54 CET 2020


>
> From: Valentin Micic
>
> I’ve run a couple of tests on my own, and managed to reproduce your
> “second! and only second!!” packet problem.
>
> It happens under following circumstances:
>
> 1) Socket (Rx) is instructed to provide a single packet as it arrives ( as
> per {active, once} );
>
>
> 2) After receiving this packet, a call to gen_udp:recv( Rx, 0, 0 ) is
> executed before another packet has ARRIVED to the kernel buffer;
>
> Then the following diagram illustrates the problem:
>
> Note:
>     - Tx is sending socket;
>     - Rx is receiving socket;
>
> *Please note that sequence diagrams below are not completely accurate, but
> it is reasonably illustrative of what may have happened.*
>
>
>
> The next sequence diagram depicts a situation when a non-zero value for
> gen_udp:recv/3, e.g. gen_udp:recv( Rx, 0, *10* ):
>
>
>
>
> Thus, it appears that gen_udp:recv( *Socket, Length*, *Timeout* ) is
> broken when *Timeout* is set to *0*.
> For all positive non-zero values for Timeout, it behaves properly (or as
> intuitively expected).
>
> Therefore, this should either be fixed, or it should be documented in
> order to indicate that 0 must *not* be used as a value for the Timeout in
> gen_udp:recv/3 call.
>
> Aside, I fail to see a benefit of using Timeout of value 0 when combined
> with {active, once}. The only time when zero value may appear to be useful
> is when server does need to process other messages, e.g. messages not
> originated by the socket, which would be the case when gen_server is used
> to support the socket. In my view (which is supported by substantial
> empirical evidence), gen_server is not the most optimal behaviour to use
> when implementing support for sockets.
>
> Kind regards
>
> V/
>
>
So, seems like there is some buggy behavior in the erlang VM for reading
UDP messages between switching from {active, once} to gen_udp:recv(socket,
0, 0)? Lukas, Raimo could you help with that?

-- 
Петровский Александр / Alexander Petrovsky,

Skype: askjuise
Phone: +7 931 9877991
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200207/81f96f65/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-3.png
Type: image/png
Size: 154681 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200207/81f96f65/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-5.png
Type: image/png
Size: 133160 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200207/81f96f65/attachment-0001.png>


More information about the erlang-questions mailing list