Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: docs for UDS data client/server #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions chaos-tproxy-controller/src/proxy/uds_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ use tokio::io::AsyncWriteExt;
use tokio::net::UnixListener;

#[derive(Debug, Clone)]

/// UdsDataServer is designed **ONLY** for communicate between chaos-tproxy main process and chaos-tproxy child process.
/// It's not a general purpose Unix Domain Socket server.
///
/// UdsDataServer would listen to certain path, and waiting for the connection from chaos-tproxy child process. Once the
/// client connect, it would send the serialized data to the client immediately.
///
/// See [chaos_tproxy_proxy::uds_client::UdsDataClient] for opposite side logics.
pub struct UdsDataServer<T> {
pub data: T,
pub path: PathBuf,
Expand All @@ -25,6 +33,11 @@ impl<T: serde::ser::Serialize> UdsDataServer<T> {
Ok(())
}

/// listen would listen on the target Unix Domain Socket path, and waiting for the connection from chaos-tproxy,
/// child, once the client connect, it would send the serialized data to the client immediately.
///
/// It would block the current thread, so it's recommended to call this method in a new thread.
/// TODO(@STRRL): graceful shutdown is not supported yet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO(@STRRL): graceful shutdown is not supported yet
UDS will automatic shutdown here. IMO, we do not need graceful shutdown here.

Copy link
Member Author

@STRRL STRRL Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UDS will automatic shutdown here. IMO, we do not need graceful shutdown here.

It seems the UDS server would not be reused between multiple Proxy::reload(), and it would keep aceept() inside the infinite loop, and the listener already moved into the inner scope, there is nowhere to "drop" it.

If I am correct, that's a resource leak.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it. It truely leaks. I agree with you . But this is not problem here. We will not meet leak only with UDS server . We leak because we spawn a blocking server.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add TODO here

pub async fn listen(&self, listener: UnixListener) -> anyhow::Result<()> {
tracing::info!("Uds listener listening on {:?}", &self.path);
loop {
Expand Down
9 changes: 9 additions & 0 deletions chaos-tproxy-proxy/src/uds_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use std::path::PathBuf;
use tokio::io::AsyncReadExt;
use tokio::net::UnixStream;

/// UdsDataClient is designed **ONLY** for communicate between chaos-tproxy main process and chaos-tproxy child process.
/// It's not a general purpose Unix Domain Socket client.
///
/// UdsDataClient would create a connection to a certain Unix Domain Socket, and read the serialized data from that
/// socket, then try to deserialize data to the required type.
#[derive(Debug, Clone)]
pub struct UdsDataClient {
pub path: PathBuf,
Expand All @@ -13,6 +18,10 @@ impl UdsDataClient {
Self { path }
}

/// read_into would create a new connection to the target Unix Domain Socket and receive the serialized data from
/// server-side, then try to deserialize data to the required type.
///
/// It would establish a new connection every time, so it's safe to call this method multiple times.
pub async fn read_into<'a, T: serde::de::Deserialize<'a>>(
&self,
buf: &'a mut Vec<u8>,
Expand Down