Search before asking
Version
OS is NixOS from a nixpkgs instance checked out at a9e7b5456522e9ee5857bb9812f27864d8e80f8a
Kvrocks: 2.16.0
Minimal reproduce step
Configure kvrocks with config:
daemonize no
dir /var/lib/kvrocks
socket-fd 3
supervised systemd
unixsocket /run/kvrocks/kvrocks.sock
And socket activate with systemd socket unit:
[Socket]
Accept=false
SocketGroup=kvrocks
SocketUser=kvrocks
ListenStream=/run/kvrocks/kvrocks.sock
[Install]
WantedBy=sockets.target
Systemd service:
[Unit]
After=network.target kvrocks.socket
Requires=kvrocks.socket
[Service]
Type=notify
User=kvrocks
Group=kvrocks
ExecStart=/usr/bin/kvrocks -c /etc/kvrocks/kvrocks.conf
[Install]
WantedBy=multi-user.target
What did you expect to see?
I expected kvrocks to pick up the unix socket provided on fd 3 and use it to listen for connections.
What did you see instead?
From journal:
systemd[1]: Starting Kvrocks - Distributed key value database...
kvrocks[1714]: [2026-08-11T15:45:19.154330+00:00][I][main.cc:171] kvrocks version 2.16.0
systemd[1]: Started Kvrocks - Distributed key value database.
kvrocks[1714]: [2026-08-11T15:45:19.214740+00:00][I][storage.cc:410] [storage] Success to load the data from disk: 49 ms
kvrocks[1714]: [2026-08-11T15:45:19.221324+00:00][E][worker.cc:66] [worker] Failed to listen to socket with fd: 3, Error: The port of the provided socket fd doesn't match the configured port
systemd[1]: kvrocks.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: kvrocks.service: Failed with result 'exit-code'.
Anything Else?
Error triggered here:
|
Status Worker::listenFD(int fd, uint32_t expected_port, int backlog) { |
|
const uint32_t port = util::GetLocalPort(fd); |
|
if (port != expected_port) { |
|
return {Status::NotOK, "The port of the provided socket fd doesn't match the configured port"}; |
|
} |
Implementation of util::GetLocalPort for context:
|
int GetLocalPort(int fd) { |
|
sockaddr_in6 address; |
|
socklen_t len = sizeof(address); |
|
if (getsockname(fd, (sockaddr *)&address, &len) == -1) { |
|
return 0; |
|
} |
|
|
|
if (address.sin6_family == AF_INET) { |
|
return ntohs(reinterpret_cast<sockaddr_in *>(&address)->sin_port); |
|
} else if (address.sin6_family == AF_INET6) { |
|
return ntohs(address.sin6_port); |
|
} |
|
|
|
return 0; |
|
} |
I'm not entirely sure if the socket-fd field is only intended for workers, but assuming it is not (or maybe even if it is), I don't think it should need to care about whether the port aligns with whatever is set in the config. Whatever provided the file descriptor can be in charge of the chosen port/socket path.
I'd be willing to submit a PR, but I'm not sure what direction you'd like to take this in, so I'll wait for input.
Are you willing to submit a PR?
Search before asking
Version
OS is NixOS from a nixpkgs instance checked out at
a9e7b5456522e9ee5857bb9812f27864d8e80f8aKvrocks:
2.16.0Minimal reproduce step
Configure kvrocks with config:
And socket activate with systemd socket unit:
Systemd service:
What did you expect to see?
I expected kvrocks to pick up the unix socket provided on fd 3 and use it to listen for connections.
What did you see instead?
From journal:
Anything Else?
Error triggered here:
kvrocks/src/server/worker.cc
Lines 232 to 236 in 3c1ac18
Implementation of
util::GetLocalPortfor context:kvrocks/src/common/io_util.cc
Lines 350 to 364 in 3c1ac18
I'm not entirely sure if the
socket-fdfield is only intended for workers, but assuming it is not (or maybe even if it is), I don't think it should need to care about whether the port aligns with whatever is set in the config. Whatever provided the file descriptor can be in charge of the chosen port/socket path.I'd be willing to submit a PR, but I'm not sure what direction you'd like to take this in, so I'll wait for input.
Are you willing to submit a PR?