question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loopback host address ('localhost','127.0.0.1', etc.) resolves to network IP

See original GitHub issue

Expected behavior

I have my Jedis client configured to connect to localhost. I expect the connection to be made to the localhost via loopback.

Actual behavior

As of the changes in https://github.com/xetorthio/jedis/pull/1342, when specifying a localhost address, it now resolves to my machine’s network ip address.

This makes it impossible to connect to a redis-sentinel on localhost because the sentinel only allows connections from loopback on more recent versions of Redis.

Steps to reproduce:

  1. Initialize a Jedis 2.9.+ client with the host 'localhost'
  2. Unable to connect to local redis-sentinel (version 3.2.2) because 'localhost' resolved to an external ip (i.e. 10.1.10.254).

I think the new behavior in getLocalHostQuietly() introduces system-dependent behavior via InetAddress.getLocalHost().getHostAddress(), which does not seem to be the intent of the code.

Redis / Jedis Configuration

Jedis version:

2.9.x (since https://github.com/xetorthio/jedis/pull/1342)

Redis version:

3.2.2

Java version:

java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

4reactions
yuriyzcommented, Dec 23, 2019

One of possible workarounds is to set it explicitly

HostAndPort.setLocalhost("127.0.0.1");

then jedis will not try to resolve it.

1reaction
sazzad16commented, May 4, 2021

From Jedis 3.6.0 (due to #2445), there are two new constructors with Set<HostAndPort> sentinels param. These constructors will not convert the hosts and treat the hosts as they are provided.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is the 127.0.0.1 IP Address? - Lifewire
The IP address 127.0.0.1 is a special-purpose IPv4 address and is called the localhost or loopback address. All computers use this address ...
Read more >
How does localhost 127.0.0.1 work? - Super User
IP datagrams sent by a host to a 127.x.x.x loopback address are not passed down to the data link layer for transmission. Instead,...
Read more >
What is the difference between 127.0.0.1 and localhost
On modern computer systems, localhost as a hostname translates to an IPv4 address in the 127.0.0.0/8 (loopback) net block, usually 127.0.0.1, or ::1...
Read more >
Why does my hostname appear with the address 127.0.1.1 ...
It is (debatably) useful to have an entry in your /etc/hosts translating the machine's fully-qualified domain name into its permanent IP address.
Read more >
What is localhost? How to connect to 127.0.0.1 - IONOS
127.0.0.1 – how does loopback work? IP addresses are used within a network to communicate with each other. Each participant in the network...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found