Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

UDP packet loss #6696

Closed
gagle opened this issue Dec 13, 2013 · 13 comments
Closed

UDP packet loss #6696

gagle opened this issue Dec 13, 2013 · 13 comments

Comments

@gagle
Copy link

gagle commented Dec 13, 2013

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
@gagle
Copy link
Author

gagle commented Dec 14, 2013

@indutny
Copy link
Member

indutny commented Dec 14, 2013

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

@indutny
Copy link
Member

indutny commented Dec 25, 2013

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
Copy link

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

@gagle
Copy link
Author

gagle commented Jan 9, 2014

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

@indutny
Copy link
Member

indutny commented Jan 18, 2014

Shifted it to v0.13 milestone.

@migounette
Copy link

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
Copy link
Member

indutny commented Jan 28, 2014

Guess it is won't fix

@indutny indutny closed this as completed Jan 28, 2014
@ijroth
Copy link

ijroth commented Jul 14, 2014

@orangemocha .. Something you can help with?

@orangemocha
Copy link
Contributor

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

@mykiimike
Copy link

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
Copy link

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

@mykiimike
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants