From 59cd9098e0abd3c692c3f2cf4b7b977c91945ffa Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Thu, 15 Dec 2022 00:15:19 +0400 Subject: [PATCH] Ignore ENOBUFS when writing to VM's socket (#18) * Ignore ENOBUFS when writing to VM's socket * Hint the into() target type to the compiler to fix the build error * Fix Clippy warnings --- lib/poller.rs | 10 ++++++++-- lib/proxy/host.rs | 19 +++++++++++++++---- src/main.rs | 2 +- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/poller.rs b/lib/poller.rs index bc703ca..cddc800 100644 --- a/lib/poller.rs +++ b/lib/poller.rs @@ -52,8 +52,14 @@ impl Poller { self.poller .wait(&mut self.events, Some(Duration::from_millis(100)))?; - let vm_readable = self.events.iter().any(|ev| ev.key == EventKey::VM.into()); - let host_readable = self.events.iter().any(|ev| ev.key == EventKey::Host.into()); + let vm_readable = self + .events + .iter() + .any(|ev| ev.key == Into::::into(EventKey::VM)); + let host_readable = self + .events + .iter() + .any(|ev| ev.key == Into::::into(EventKey::Host)); Ok((vm_readable, host_readable)) } diff --git a/lib/proxy/host.rs b/lib/proxy/host.rs index af0d9d3..b01feac 100644 --- a/lib/proxy/host.rs +++ b/lib/proxy/host.rs @@ -16,10 +16,21 @@ impl Proxy { self.snoop(frame); } - self.vm - .write(frame.as_ref()) - .map(|_| ()) - .context("failed to write to the VM") + match self.vm.write(frame.as_ref()) { + Ok(_) => Ok(()), + Err(err) => { + if let Some(libc::ENOBUFS) = err.raw_os_error() { + sentry::capture_message( + "No buffer space available in VM's socket", + sentry::Level::Warning, + ); + + return Ok(()); + } + + Err(err).context("failed to write to the VM") + } + } } fn allowed_from_host(&mut self, frame: &EthernetFrame<&[u8]>) -> Option<()> { diff --git a/src/main.rs b/src/main.rs index 73bf1ee..fdee623 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ fn main() -> ExitCode { // Enrich future events with Cirrus CI-specific tags if let Ok(tags) = env::var("CIRRUS_SENTRY_TAGS") { sentry::configure_scope(|scope| { - for (key, value) in tags.split(",").map(|tag| tag.split_once("=")).flatten() { + for (key, value) in tags.split(',').filter_map(|tag| tag.split_once('=')) { scope.set_tag(key, value); } });