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

socket.setTimeout malfunction when timeout is string #8618

@weihua44

Description

@weihua44

Test the following code,
node tst

telnet localhost 10015, the connection will be lost in 1 second
telnet locahost 10016 then telnet localhost 10015, the connection will not be lost (it means the timeout event is failed for some reason)
If you change the var "to" from string to int, the timeout will always working.

<<File: tst.js>>

var net = require('net');

var clilistener = net.createServer(function(c) {
    var to  = '1000';
//  var to  = 1000;
    var mark    = 'svr1:';
    console.log(mark+'cli connected from '+c.remoteAddress+':'+c.remotePort);
    console.log(mark+'set timeout to '+to);
    c.setTimeout(to, function() {
        console.log(mark+'time out arrived...');
        c.destroy();
    });
    c.on('error', function(err) {
        c.destroy();
    });
    c.on('close', function(isErr) {
        console.log(mark+'cli out');
    });
    //
});
clilistener.listen(10015);

var clilistener = net.createServer(function(c) {
    var to  = '60000';
//  var to  = 60000;
    var mark    = 'svr1:';
    console.log(mark+'cli connected from '+c.remoteAddress+':'+c.remotePort);
    console.log(mark+'set timeout to '+to);
    c.setTimeout(to, function() {
        console.log(mark+'time out arrived...');
        c.destroy();
    });
    c.on('error', function(err) {
        c.destroy();
    });
    c.on('close', function(isErr) {
        console.log(mark+'cli out');
    });
    //
});
clilistener.listen(10016);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions