Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

UDP packet loss #6696

Closed
gagle opened this Issue · 13 comments

7 participants

@gagle

Node v0.10.22
Windows 7 x64

The UDP socket (as a client) doesn't return all the packets that the server sends in this scenario:

  • Packet size: 1468 (maximum size before packet fragmentation).
  • The server sends more than 6 packets at the same time.

The following example does:

  • The first byte of each packet represents the block number.
  • The client sends the first block (0).
  • The server responds with 10 blocks (1..10).
  • The client receives less than 10 blocks. This is random, sometimes it receives 6 packets, sometimes it receives 7.

Note: If the server sends less than 7 packets each time, the client receives all the blocks. If the server sends more than 6 packets BUT you change the size of each of them (e.g. 10 bytes) the client receives all the blocks.

Server:

"use strict";

var dgram = require ("dgram");
var crypto = require ("crypto");

crypto.randomBytes (1467, function (error, buffer){
    if (error) return console.error (error);

    var send = function (n, rinfo){
        socket.send (Buffer.concat ([new Buffer ([n]), buffer], 1468), 0, 1468,
                rinfo.port, rinfo.address, function (){
                    console.log (">> " + n);
                });
    };

    var socket = dgram.createSocket ("udp4")
            .on ("error", function (error){
                console.error (error);
            })
            .on ("message", function (message, rinfo){
                console.log ("<< " + message.readUInt8 (0));

                send (1, rinfo);
                send (2, rinfo);
                send (3, rinfo);
                send (4, rinfo);
                send (5, rinfo);
                send (6, rinfo);
                send (7, rinfo);
                send (8, rinfo);
                send (9, rinfo);
                send (10, rinfo);
            });

    socket.bind (1337);
});

Client:

"use strict";

var dgram = require ("dgram");
var crypto = require ("crypto");

var socket = dgram.createSocket ("udp4")
        .on ("error", function (error){
            console.error (error);
        })
        .on ("message", function (message){
            console.log ("<< " + message.readUInt8 (0));
        });

crypto.randomBytes (1467, function (error, buffer){
    if (error) return console.error (error);

    socket.send (Buffer.concat ([new Buffer ([0]), buffer], 1468), 0, 1468, 1337,
            "localhost", function (error){
                if (error) return console.error (error);
                console.log (">> " + 0);
            });
});

RESULT

Client:

>> 0
<< 1
<< 2
<< 3
<< 4
<< 5
<< 6
<< 7

Server:

<< 0
>> 1
>> 2
>> 3
>> 4
>> 5
>> 6
>> 7
>> 8
>> 9
>> 10
@indutny
Owner

Just for future reference, seems to be working fine on unixes.

@indutny
Owner

It looks like windows is just discarding the rest of them. @piscisaureus may I ask you to take a look at this? I have no time to work on windows stuff, but if you won't find time either - I'll look into it in a month...

@trevnorris
Owner

@gagle Have you tried this on latest v0.11?

@gagle

@trevnorris Yes, same results. The client only receives 7 packets.

@indutny
Owner

Shifted it to v0.13 milestone.

@migounette

My 2 cents

Works fine too on Windows 8.1 & NodeJS v0.11.10

c:\temp>node client.js

0
<< 1
<< 2
<< 3
<< 4
<< 5
<< 6
<< 7
<< 8
<< 9
<< 10

c:\temp>node server.js
<< 0

1
2
3
4
5
6
7
8
9
10

@indutny
Owner

Guess it is won't fix

@indutny indutny closed this
@ijroth

@orangemocha .. Something you can help with?

@orangemocha
Owner

I can definitely investigate, but not for some time. Stuff on my plate is piling up faster than I can fix it lately.

@mykiimike

I got the same problem on Linux ... I use the UDP multi/unicast to manage heartbeats between servers and sometime w/o any really reasons i lose "connection" while the HB timeout is very high (about 10 seconds), the HB packet interval is 500ms and for long time i got some packets dropped.

Linux - 3.11.0-24-generic #42-Ubuntu SMP Fri Jul 4 21:19:31 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
node 0.10.29

You can find my source code there https://github.com/binarysec/gate/blob/master/src/lib/acn/js/service.js

and the doc there https://github.com/binarysec/gate/wiki/AssociativeCacheNetwork

@trevnorris
Owner

@mykiimike Thanks for source that doesn't depend on any external modules. Have you tried running this on latest v0.11?

@mykiimike

@trevnorris no but i can/will try it Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.