-
Notifications
You must be signed in to change notification settings - Fork 459
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
feat(worker): Allow passing a socket FD to dup and listen on #2598
Conversation
The implementation looks good. But could you elabrate more about the use case? i.e. in which cases it's better than connecting to tcp/unix sockets? Maybe you can attach a shell script or something to illustrate it. |
Currently, the Kvrocks port listening implementation has a race condition: since Kvrocks checks whether the port is in use before actually grabbing exclusive use of the port, it's possible to spawn two Kvrocks servers listening on the same ports. The minimal repro of this is to run As such, I have a script like below which reserves a port, and passes the socket's FD to spawn Kvrocks: import socket
s = socket.create_server(...) # Grab a port which is guaranteed to be free
port = s.getsockname()[1]
socket_fd = s.fileno()
subprocess.run(f"./kvrocks --port {port} --socket-fd {socket_fd}")
# Now, Kvrocks can safely duplicate and use the FD `socket_fd` without fear of other Kvrocks instances trampling it |
Quality Gate failedFailed conditions |
When spawning Kvrocks as a part of a script, it's sometimes helpful to first reserve a port with a socket, and pass that socket to Kvrocks as a child process.
This change implements this change:
socket-fd
which defaults to -1 (no fd specified).socket-fd
is provided, will skip checking that the supplied port is available (since it will already be grabbed by the provided fd). Instead, it will check that the supplied fd is indeed a socket associated to the provided port.socket-fd
is provided,Worker
's willdup
the supplied fd and listen to that instead of trying to make their own socket from scratch.socket-fd
on shut-down.As a bonus, removed some unneeded indirect includes and cleaned up some surrounding code.