Describe the bug
When running redis with --unixsocket or the unixsocket config option, the path given is assumed to be absolute even if it does not have a leading slash. For example,
redis-server --dir "data/redis" --pidfile "data/redis/redis-dev.pid" --unixsocket "data/redis/redis-dev.sock" results in:
18026:C 25 Nov 2022 15:30:01.079 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18026:C 25 Nov 2022 15:30:01.079 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=18026, just started
18026:C 25 Nov 2022 15:30:01.079 # Configuration loaded
18026:M 25 Nov 2022 15:30:01.080 * monotonic clock: POSIX clock_gettime
18026:M 25 Nov 2022 15:30:01.080 # Failed opening Unix socket: bind: No such file or directory
while (in our case):
redis-server --dir "data/redis" --pidfile "data/redis/redis-dev.pid" --unixsocket "/home/[USER]/data/redis/redis-dev.sock" works as intended:
18384:C 25 Nov 2022 15:32:56.106 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18384:C 25 Nov 2022 15:32:56.106 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=18384, just started
18384:C 25 Nov 2022 15:32:56.106 # Configuration loaded
18384:M 25 Nov 2022 15:32:56.106 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 7.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 18384
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
18384:M 25 Nov 2022 15:32:56.107 # Server initialized
18384:M 25 Nov 2022 15:32:56.107 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
18384:M 25 Nov 2022 15:32:56.107 * Loading RDB produced by version 7.0.5
18384:M 25 Nov 2022 15:32:56.107 * RDB age 181 seconds
18384:M 25 Nov 2022 15:32:56.107 * RDB memory usage when created 0.84 Mb
18384:M 25 Nov 2022 15:32:56.107 * Done loading RDB, keys loaded: 0, keys expired: 0.
18384:M 25 Nov 2022 15:32:56.107 * DB loaded from disk: 0.000 seconds
18384:M 25 Nov 2022 15:32:56.107 * Ready to accept connections
To reproduce
Run a redis-server command with --unixsocket data/redis-dev.sock where data is a subdirectory of the current directory that is writable by the current user
Expected behavior
Giving relative paths to redis-server for --unixsocket and the unixsocket config option should work.
Comment From: AtelierSnek
Oh, this is because --unixsocket is relative to --dir but --pidfile does not seem to be.
This should be consistent one way or the other.
Comment From: madolson
I'm not sure I quite follow. You pass in data/redis as the --dir, which changes the relative path to that directory. So in your example, you're setting the unix socket and pid to data/redis/data/redis since you're first changing the relative directory and then passing in further relative directory arguments.
I have a suspicion the pid file is also failing to be written, but we aren't logging any error in that case since it is considered a best effort failure. I made a small patch to fix that, https://github.com/redis/redis/pull/11544, but I'm still of the opinion that there is no other issue.
Comment From: AtelierSnek
Ah, yeah that seems to be the behaviour we're seeing. Thanks. If it's issuing a warning now, that's good :)