Skip to content

Redis connection "redis:///var/run/redis/redis.sock" failed: php_network_getaddresses: getaddrinfo failed: Name or service not known #45277

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

Closed
wokenlex opened this issue Feb 2, 2022 · 1 comment

Comments

@wokenlex
Copy link

wokenlex commented Feb 2, 2022

Symfony version(s) affected

v4.4.37

Description

After update from v4.4.27 to v4.4.37 symfony cache can't connect redis through the socket.

How to reproduce

Use socket connection to redis, use URL in redis config like this:
redis:///var/run/redis/redis.sock

Possible Solution

No response

Additional Context

No response

@mathielen
Copy link
Contributor

It's because in this commit c0879ec the default for $port has been set to 6379 instead of null. So the redis connection is using a port with a unix-socket. This throws a RedisException with php_network_getaddresses: getaddrinfo failed: Name or service not known

nicolas-grekas added a commit that referenced this issue Feb 4, 2022
…v80)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] Fix connecting to Redis via a socket file

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #45277
| License       | MIT
| Doc PR        |

In the [commit](99b4885) was done follow changes in Traits/RedisTrait.php(188)

Old code:

```$port = $hosts[0]['port'] ?? null;```

New code:

```$port = $hosts[0]['port'] ?? 6379;```

With DSN "redis:///var/run/redis/redis.sock" raise an error:

```
Redis connection "redis:///var/run/redis/redis.sock?dbindex=5" failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
```

Because phpredis doesn't allow socket connections with a port

```
(new Redis)->connect('/var/run/redis/redis.sock', 6379);
```

**Error**

```
PHP Warning:  Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/test_redis.php on line 5
PHP Fatal error:  Uncaught RedisException: php_network_getaddresses: getaddrinfo failed: Name or service not known in /root/test_redis.php:5
Stack trace:
#0 /root/test_redis.php(5): Redis->connect()
#1 {main}
  thrown in /root/test_redis.php on line 5
```

I added additional validation of connection type (by host or socket). Also I fixed condition when RedisSentinel connection call as it supports connections by host only.

Commits
-------

214fdd1 [Cache] Fix connecting to Redis via a socket file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants