linux: Set recv timeout for balloon_host_tube to avoid deadlock

Before this change, crosvm process will be stall when `crosvm
balloon_stats` command is called before the first message is received
because the logic waits reply from balloon device forever and it blocks
the VM going forward.
This CL sets recv timeout on balloon_host_tube to unblock the execution
in such case.

BUG=None
TEST=Sent `crosvm ballon_stats <socket>` command right after crosvm
started and observed Resource temporarily unavailable error instead of
stall.

Change-Id: I9e7716fdbd3493846993d0a3f727eed2043df4c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2909697
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Hikaru Nishida <hikalium@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Charles William Dick <cwd@google.com>
This commit is contained in:
Hikaru Nishida 2021-05-21 12:03:54 +09:00 committed by Commit Bot
parent e6bf005d26
commit af3f3bbecd

View file

@ -2513,6 +2513,10 @@ where
control_tubes.push(TaggedControlTube::VmMemory(wayland_host_tube));
// Balloon gets a special socket so balloon requests can be forwarded from the main process.
let (balloon_host_tube, balloon_device_tube) = Tube::pair().map_err(Error::CreateTube)?;
// Set recv timeout to avoid deadlock on sending BalloonControlCommand before guest is ready.
balloon_host_tube
.set_recv_timeout(Some(Duration::from_millis(100)))
.map_err(Error::CreateTube)?;
// Create one control socket per disk.
let mut disk_device_tubes = Vec::new();