node.js - Why NodeJS KeepAlive does not seem to work as expected? -


quoted tcp keepalive howto:

in order understand tcp keepalive (which call keepalive) does, need nothing more read name: keep tcp alive. means able check connected socket (also known tcp sockets), , determine whether connection still , running or if has broken.

so why following code not throwing something when internet connection broken?

var tls = require('tls');  var socket = tls.connect(443, "google.com", function connected() {   console.log('connected'); });  socket.setnodelay(true); socket.setkeepalive(true, 0); socket.settimeout(0, function(){   console.log('timeout'); }); socket.on('data', function(data) {   console.log(data); }); socket.on('close', function() {   console.error("close"); }); socket.on('error', function(err) {   console.error("error", err); }); 

tested on macos/debian, nodejs v0.10.17

quoting man 7 tcp:

tcp_keepalive_time (integer; default: 7200; since linux 2.2)

the number of seconds connection needs idle before tcp begins sending out keep-alive probes. keep-alives sent when so_keepalive socket option enabled. default value 7200 seconds (2 hours). idle connection terminated after approximately an additional 11 minutes (9 probes interval of 75 seconds apart) when keep-alive enabled.

so after ~10 minutes (on macos 10.8) node emitted error:

error { [error: read etimedout] code: 'etimedout', errno: 'etimedout', syscall: 'read' } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -