Skip to content

0.12.7 vs 4.1.1 - Are there some changes in net.Socket? #3056

Closed
@o5

Description

@o5

Hi,

I created a small micro-service called "Port Checker Tool", but today, I tried to upgrade from v0.12.7 to v4.1.1 but service doesn't work for now.

I prepared a small code for reproduction. It does nothing special, it creates a HTTP server, listen on port 8000 and when you open http://localhost:8000/start in your browser, it will create a sync queue with ports for checking connection (is connection on some port is open or not). I'm using a last version of async library "async": "~1.4.2".

index.js

var Http = require('http'),
    Net  = require('net'),
    Async = require('async');

var server = Http.createServer(function(request, response) {
    if (request.url === '/start') {
        var queue = Async.queue(function(port, done) {

            console.time('PORT:' + port);

            var socket = new Net.Socket();
            socket.setTimeout(1000);

            socket.connect(port, '173.194.122.7', function () {
                console.timeEnd('PORT:' + port);
                console.log('OPEN\n');
                socket.destroy();
                done();
            });

            socket.on('error', function (e) {
                console.timeEnd('PORT:' + port);
                console.log('ERROR:', e, '\n');
                socket.destroy();
                done();
            });

            socket.on('timeout', function () {
                console.timeEnd('PORT:' + port);
                console.log('CLOSED\n');
                socket.destroy();
                done();
            });
        }, 1);

        queue.push([70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90]);
        queue.drain = function() {
            console.log('THE END!');
        };
    }

    response.end('OK');
});

server.listen(8000);

There are two differences when node is 4.1.1

  1. some timeouts aren't ~1000ms
  2. some check ends with error

There is an output from terminal, when I use an old version of Node.

[~/]$ node -v
v0.12.7

[~/]$ node index.js
PORT:70: 1009ms
CLOSED

PORT:72: 1002ms
CLOSED

PORT:74: 1004ms
CLOSED

PORT:76: 1003ms
CLOSED

PORT:78: 1005ms
CLOSED

PORT:80: 15ms
OPEN

PORT:82: 1003ms
CLOSED

PORT:84: 1004ms
CLOSED

PORT:86: 1003ms
CLOSED

PORT:88: 1004ms
CLOSED

PORT:90: 1004ms
CLOSED

THE END!

and there for new Node.js.

[~/]$ node -v
v4.1.1

[~/]$ node index.js
PORT:70: 1007ms
CLOSED

PORT:72: 75187ms
ERROR: { [Error: connect ETIMEDOUT 173.194.122.7:72]
  code: 'ETIMEDOUT',
  errno: 'ETIMEDOUT',
  syscall: 'connect',
  address: '173.194.122.7',
  port: 72 }

PORT:74: 1002ms
CLOSED

PORT:76: 43151ms
CLOSED

PORT:78: 1003ms
CLOSED

PORT:80: 61ms
OPEN

PORT:82: 1005ms
CLOSED

PORT:84: 1004ms
CLOSED

PORT:86: 1003ms
CLOSED

PORT:88: 1003ms
CLOSED

PORT:90: 1006ms
CLOSED

THE END!

Maybe, I have something wrong with my code which work only with old version of node.

OSX 10.10.5

Thank you!

Metadata

Metadata

Assignees

Labels

netIssues and PRs related to the net subsystem.questionIssues that look for answers.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions