pojntfx / go-nbd

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

client.Connect() never returns #1

Closed bduffany closed 1 year ago

bduffany commented 1 year ago

I am working on an application in which an nbd may be swapped out for another one, using a long-running client process (an agent running inside a VM).

The approach I'm thinking of using is to call client.Disconnect() then umount the nbd.

However, for my particular case, this repeated connect/disconnect approach would result in a goroutine leak, because client.Connect() never returns. It is getting stuck in the <-fatal channel recv at the end of the func, which never receives a fatal error even if I call conn.Close() and close the file descriptor with f.Close().

Is it possible to have this function return once the device is connected? (Maybe instead of the OnConnected callback, just always do the connection check, and have Connect() return a nil error if and only if the connection is established successfully. Or if it's desired to make the connection check optional, have a separate func to explicitly wait for the device to be ready. Maybe there could be separate funcs for Udev vs. polling /sys/block, like WaitForReadyUdev / WaitForReady.)

pojntfx commented 1 year ago

Hi! Sorry, completely missed this. That is indeed an interesting problem you are facing, but since this is using the kernel's internal NBD cient there isn't too much I can do here since the underlying NBD_DO_IT ioctl never returns in your usecase, or am I missing something?