go-nbd icon indicating copy to clipboard operation
go-nbd copied to clipboard

Support PID file or some indication that the server has started

Open rwmjones opened this issue 1 year ago • 2 comments

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 avatar Mar 24 '24 15:03 rwmjones

(Adding @ebblake)

rwmjones avatar Mar 24 '24 15:03 rwmjones

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.

ebblake avatar Mar 27 '24 14:03 ebblake

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.

pojntfx avatar Jul 30 '24 23:07 pojntfx