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

Support set deadline for qmp socket connection

Open MaJin1996 opened this issue 1 year ago • 0 comments

If some other process(e.g. libvirtd) occupy the qmp socket, run command will hang.

Sometimes we use go-qemu to take over VM when libvirtd stopped, but libvirtd service will start automatically at an undetermined time. Deadline could prevent the impact of race condition.

example: `

socket, err := qmp.NewSocketMonitor("unix", sockFile, timeout)

if err != nil {
	return nil, err
}

if err := socket.SetRWDeadline(time.Now().Add(timeout)); err != nil {
	return nil, err
}

if err := socket.Connect(); err != nil {
	return nil, err
}
defer socket.Disconnect()

`

MaJin1996 avatar Oct 07 '23 09:10 MaJin1996