diff --git a/ipc/src/platform/unix/channel.rs b/ipc/src/platform/unix/channel.rs index 527483b2d..be4eae588 100644 --- a/ipc/src/platform/unix/channel.rs +++ b/ipc/src/platform/unix/channel.rs @@ -101,10 +101,7 @@ impl Write for Channel { "failed to write whole buffer", )); } - Ok(n) => { - self.metadata.defer_close_handles(handles); - buf = &buf[n..] - } + Ok(n) => buf = &buf[n..], Err(ref e) if e.kind() == ErrorKind::Interrupted => {} Err(e) => { self.metadata.reenqueue_for_sending(handles); diff --git a/ipc/src/platform/unix/channel/async_channel.rs b/ipc/src/platform/unix/channel/async_channel.rs index 476a12a1e..3b525ed4e 100644 --- a/ipc/src/platform/unix/channel/async_channel.rs +++ b/ipc/src/platform/unix/channel/async_channel.rs @@ -61,14 +61,7 @@ impl AsyncWrite for AsyncChannel { if !handles.is_empty() { let fds: Vec = handles.iter().map(AsRawFd::as_raw_fd).collect(); match project.inner.send_with_fd(buf, &fds) { - Ok(sent) => { - project - .metadata - .lock() - .unwrap() - .defer_close_handles(handles); - Poll::Ready(Ok(sent)) - } + Ok(sent) => Poll::Ready(Ok(sent)), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { project .metadata diff --git a/ipc/src/platform/unix/channel/metadata.rs b/ipc/src/platform/unix/channel/metadata.rs index 9cd131ec0..f456fed5b 100644 --- a/ipc/src/platform/unix/channel/metadata.rs +++ b/ipc/src/platform/unix/channel/metadata.rs @@ -2,9 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 use std::{ - collections::{BTreeMap, VecDeque}, + collections::VecDeque, io, - os::unix::prelude::{AsRawFd, FromRawFd, IntoRawFd, RawFd}, + os::unix::prelude::{AsRawFd, FromRawFd, RawFd}, }; use io_lifetimes::OwnedFd; @@ -18,8 +18,6 @@ use crate::{ pub struct ChannelMetadata { fds_to_send: Vec>, fds_received: VecDeque, - fds_acked: Vec, - fds_to_close: BTreeMap>, pid: libc::pid_t, // must always be set to current Process ID } @@ -28,8 +26,6 @@ impl Default for ChannelMetadata { Self { fds_to_send: Default::default(), fds_received: Default::default(), - fds_acked: Default::default(), - fds_to_close: Default::default(), pid: nix::unistd::getpid().as_raw(), } } @@ -40,27 +36,6 @@ impl ChannelMetadata { where T: TransferHandles, { - { - let fds_to_close = message - .acked_handles - .into_iter() - .flat_map(|fd| self.fds_to_close.remove(&fd)); - - // if ACK came from the same PID, it means there is a duplicate PlatformHandle instance - // in the same process. Thus we should leak the handles allowing other - // PlatformHandle's to safely close - if message.pid == self.pid { - for h in fds_to_close { - h.into_owned_handle() - .map(|h| h.into_raw_fd()) - .unwrap_or_default(); - } - } else { - // drain iterator closing all open file desriptors that were ACKed by the other - // party - fds_to_close.last(); - } - } let mut item = message.item; item.receive_handles(self)?; @@ -75,18 +50,12 @@ impl ChannelMetadata { let message = Message { item, - acked_handles: self.fds_acked.drain(..).collect(), pid: self.pid, }; Ok(message) } - pub(crate) fn defer_close_handles(&mut self, handles: Vec>) { - let handles = handles.into_iter().map(|h| (h.as_raw_fd(), h.to_untyped())); - self.fds_to_close.extend(handles); - } - pub(crate) fn enqueue_for_sending(&mut self, handle: PlatformHandle) { self.fds_to_send.push(handle.to_untyped()) } diff --git a/ipc/src/platform/unix/message.rs b/ipc/src/platform/unix/message.rs index 5add80c49..0e583169c 100644 --- a/ipc/src/platform/unix/message.rs +++ b/ipc/src/platform/unix/message.rs @@ -1,8 +1,6 @@ // Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use std::os::unix::prelude::RawFd; - use serde::{Deserialize, Serialize}; /// sendfd crate's API is not able to resize the received FD container. @@ -13,6 +11,5 @@ pub const MAX_FDS: usize = 20; #[derive(Deserialize, Serialize)] pub struct Message { pub item: Item, - pub acked_handles: Vec, pub pid: libc::pid_t, }