Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncatchable crash if ping command not available - returns "spawn ping ENOENT" #342

Open
kevinburkenotion opened this issue Mar 26, 2019 · 1 comment

Comments

@kevinburkenotion
Copy link

If you get in a state where memcached attempts to reconnect, it will call ping(this.tokens[1]), which attempts to spawn a binary to call ping -c 3. The ping function in Javascript does not handle the case where the ping binary is not present - specifically it's missing an .on(error) handler that could catch the situation where ping is not found, has the wrong permissions, or the running process does not have permission to spawn children.

function ping (host, callback) {
  var isWin = process.platform.indexOf('win') === 0; // win32 or win64
  var arg = isWin ? '-n' : '-c';
  var pong = spawn('ping', [arg, '3', host]); // only ping 3 times

  pong.stdout.on('data', function stdoutdata (data) {
    callback(false, data.toString().split('\n')[0].substr(14));
    pong.kill();
  });

  pong.stderr.on('data', function stderrdata (data) {
    callback(new Error(data.toString().split('\n')[0].substr(14)), false);
    pong.kill();
  });
}

The lack of a .on('error') handler means that any failure here is uncatchable and crashes the process.

More broadly I have to wonder about the effectiveness of calling ping if a connection fails - it's not clear that one TCP packet is going to have any more luck than another if the connection is in trouble.

@aakarsh
Copy link

aakarsh commented Nov 15, 2019

+1 We are seeing this as well please let us know if you are you accepting patches, that do not spawn a separate process for a ping availability check?

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

No branches or pull requests

2 participants