From d17aa6471013fa2e3765738680304cc7839c7205 Mon Sep 17 00:00:00 2001 From: J M Date: Sat, 7 Oct 2023 17:21:12 +0800 Subject: [PATCH] Support set deadline for qmp socket connection 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. --- qmp/socket.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qmp/socket.go b/qmp/socket.go index c929a77..4890af5 100644 --- a/qmp/socket.go +++ b/qmp/socket.go @@ -166,6 +166,13 @@ func (mon *SocketMonitor) Events(context.Context) (<-chan Event, error) { return mon.events, nil } +// SetRWDeadline sets the read and write deadlines for the underlying socket. +// Set deadline to prevent the Command from hanging due to other processes +// (e.g. libvirt) occupying the QEMU monitor socket. +func (mon *SocketMonitor) SetRWDeadline(t time.Time) error { + return mon.c.SetDeadline(t) +} + // listen listens for incoming data from a QEMU monitor socket. It determines // if the data is an asynchronous event or a response to a command, and returns // the data on the appropriate channel.