Why NodeJS KeepAlive does not seem to work as expected?

FGRibreau

Quoted from TCP keepalive HowTo:

In order to understand what TCP keepalive (which we will just call keepalive) does, you need do nothing more than read the name: keep TCP alive. This means that you will be able to check your connected socket (also known as TCP sockets), and determine whether the connection is still up and running or if it has broken.

So why is the following code not throwing something when the internet connection is 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, with NodeJS v0.10.17

FGRibreau

Quoting man 7 tcp:

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

The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours). An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart) when keep-alive is enabled.

So after ~10 minutes (on MacOS 10.8) node emitted an error:

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

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Query does not seem to work with enum

분류에서Dev

jQuery.each does not seem to work

분류에서Dev

In Flink, stream windowing does not seem to work?

분류에서Dev

MongoDB elemMatch does not work expected

분류에서Dev

mysql DISTINCT() does not work as expected

분류에서Dev

Regex in powershell does not work as expected

분류에서Dev

Why does ubuntu not seem to release memory?

분류에서Dev

Why and how does this work?

분류에서Dev

Why should SIGINT be triggered twice to work as expected?

분류에서Dev

Why doesn't this batch command work as expected?

분류에서Dev

My collision list does not work as expected

분류에서Dev

Simple choice function does not seem to work (C++)

분류에서Dev

Android OpenGL ES 2.0 Texture setting does not seem to work

분류에서Dev

Why does this command not remove files as expected?

분류에서Dev

NodeJS - How does 'require' work on the server?

분류에서Dev

Does D3 transition work on nodejs?

분류에서Dev

Why does pkill not work with rofi?

분류에서Dev

Why does sudo not work with curl?

분류에서Dev

Why does remove(x) not work?

분류에서Dev

Why does this angularjs directive not work?

분류에서Dev

Why does this rename operation not work?

분류에서Dev

Why does this type of inheritance work?

분류에서Dev

CSS3 blur effect does not work as expected

분류에서Dev

Calling string from one function into another doesent seem to work., why?

분류에서Dev

Why does NVL2 returns NULL when it's not expected?

분류에서Dev

Why does `find` in Linux skip expected results when `-o` is used?

분류에서Dev

Does anyone know why my AngularJS directives do not display as expected?

분류에서Dev

Websocket does not seem to connect

분류에서Dev

Why does this C code not work in JavaScript?

Related 관련 기사

뜨겁다태그

보관