pojntfx / go-nbd

Pure Go NBD server and client library.
Apache License 2.0
346 stars 18 forks source link

Support PID file or some indication that the server has started #11

Closed rwmjones closed 2 months ago

rwmjones commented 6 months ago

I'm trying to write an automated interop test for libnbd & go-nbd.

However there seems to be know way to know when the server is ready and listening for requests. This is most obviously a problem if you have a test which does:

pid = os.fork()
if pid == 0:        # run go-nbd in the child process
    os.execvp(golang, argv)

# Connect to go-nbd in the parent process
h.connect_unix(sock)

Normally we would want to have the server write a PID file when it has finished starting up and is listening for requests (note: the PID file should be written after the listening socket is opened). In the client side of the test we would wait for this file to appear.

But as go-nbd doesn't seem to do that, there's no way to safely start the test in a race-free way.

rwmjones commented 6 months ago

(Adding @ebblake)

ebblake commented 6 months ago

It would also be nice to have systemd-style socket activation, where the parent can pre-open a socket and pass one end into the child along with details in LISTEN_* environment variables, which avoids the need for the parent to wait for a pid file to appear at all.

pojntfx commented 2 months ago

This could be interesting, but it's not something that really is in the scope of this project since it's intended for the for use as a library and does intentionally not vendor any ready-to-use binaries. The library itself makes no assumptions about how you start the server not does it start the listener; you can achieve the desired effect by writing the PID file after you start the listener here.