Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.

Commit d50b2fa

Browse files
author
Wieger Steggerda
committed
Provide hint when user tries and fails to connect to localhost or 127.0.0.1.
1 parent 4a847a0 commit d50b2fa

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

lib/cluster.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var async = require('async');
2626
var AdminClient = require('./admin-client.js');
2727
var Partition = require('./partition.js');
2828
var Stats = require('./stats.js');
29+
var format = require('util').format;
30+
var startsWith = require('./util.js').startsWith;
2931

3032
function Cluster(opts) {
3133
opts = opts || {
@@ -177,7 +179,16 @@ Cluster.prototype.fetchStats = function fetchStats(callback) {
177179

178180
function onComplete(err, allStats) {
179181
if (allStats.length === 0) {
180-
callback(new Error('Failed to connect to any ringpop members'));
182+
var addr = self.coordAddr;
183+
var msg = format('Failed to connect to ringpop listening on %s.', addr);
184+
185+
// Check if user tries to connect to localhost or 127.0.0.1.
186+
if (typeof addr === 'string' &&
187+
(startsWith(addr, 'localhost') || startsWith(addr, '127.0.0.1'))) {
188+
msg += ' Ringpop ordinarily does not listen on the loopback interface. Try a different IP address.';
189+
}
190+
191+
callback(new Error(msg));
181192
return;
182193
}
183194
self.lastDownloadTime = Date.now() - downloadTime;

lib/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ function safeParse(data) {
4040
}
4141
}
4242

43+
function startsWith(str, str2) {
44+
return str.substring(0, str2.length) === str2;
45+
}
46+
4347
module.exports = {
4448
assertNoErr: assertNoError,
4549
assertNoError: assertNoError,
4650
assertTruthy: assertTruthy,
47-
safeParse: safeParse
51+
safeParse: safeParse,
52+
startsWith: startsWith
4853
};

tests/partitions.t

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ With bootstrap file:
1414

1515
Unable to connect to host:
1616

17+
$ ringpop-admin partitions 0.0.0.1:2999
18+
Error while fetching node stats: { [TchannelSocketError: tchannel socket error (* from connect): connect *] (glob)
19+
type: 'tchannel.socket',
20+
message: 'tchannel socket error (* from connect): connect *', (glob)
21+
hostPort: null,
22+
direction: 'out',
23+
remoteAddr: null,
24+
name: 'TchannelSocketError',
25+
socketRemoteAddr: '0.0.0.1:2999',
26+
causeMessage: 'connect *', (glob)
27+
origMessage: 'connect *', (glob)
28+
code: '*', (glob)
29+
errno: '*', (glob)
30+
syscall: 'connect',
31+
fullType: 'tchannel.socket~!~error.wrapped-io.connect.*' } (glob)
32+
Error: Failed to connect to ringpop listening on 0.0.0.1:2999.
33+
[1]
34+
35+
36+
Provide hint if the user tries and fails to connect to localhost or 127.0.0.1
37+
1738
$ ringpop-admin partitions 127.0.0.1:2999
1839
Error while fetching node stats: { [TchannelSocketError: tchannel socket error (ECONNREFUSED from connect): connect ECONNREFUSED]
1940
type: 'tchannel.socket',
@@ -29,5 +50,23 @@ Unable to connect to host:
2950
errno: 'ECONNREFUSED',
3051
syscall: 'connect',
3152
fullType: 'tchannel.socket~!~error.wrapped-io.connect.ECONNREFUSED' }
32-
Error: Failed to connect to any ringpop members
53+
Error: Failed to connect to ringpop listening on 127.0.0.1:2999. Ringpop ordinarily does not listen on the loopback interface. Try a different IP address.
54+
[1]
55+
56+
$ ringpop-admin partitions localhost:2999
57+
Error while fetching node stats: { [TchannelSocketError: tchannel socket error (ECONNREFUSED from connect): connect ECONNREFUSED]
58+
type: 'tchannel.socket',
59+
message: 'tchannel socket error (ECONNREFUSED from connect): connect ECONNREFUSED',
60+
hostPort: null,
61+
direction: 'out',
62+
remoteAddr: null,
63+
name: 'TchannelSocketError',
64+
socketRemoteAddr: 'localhost:2999',
65+
causeMessage: 'connect ECONNREFUSED',
66+
origMessage: 'connect ECONNREFUSED',
67+
code: 'ECONNREFUSED',
68+
errno: 'ECONNREFUSED',
69+
syscall: 'connect',
70+
fullType: 'tchannel.socket~!~error.wrapped-io.connect.ECONNREFUSED' }
71+
Error: Failed to connect to ringpop listening on localhost:2999. Ringpop ordinarily does not listen on the loopback interface. Try a different IP address.
3372
[1]

0 commit comments

Comments
 (0)