nathanlo-hrt commented on PR #2598:
URL: https://github.com/apache/kvrocks/pull/2598#issuecomment-2411838798
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 `build/kvrocks --port 8888 &
build/kvrocks --port 8888` a few times: eventually both will succeed and you'll
be able to issue commands to port 8888 and cause undefined behavior.
As such, I have a script like below which reserves a port, and passes the
socket's FD to spawn Kvrocks:
```py
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
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]