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

transport: Improve TCP server error messages #1372

Merged
merged 3 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,7 @@ dependencies = [
"linkerd-io",
"linkerd-stack",
"socket2 0.4.2",
"thiserror",
"tokio",
"tokio-stream",
"tracing",
Expand Down
9 changes: 6 additions & 3 deletions linkerd/app/core/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ pub async fn serve<M, S, I, A>(
};

// The local addr should be instrumented from the listener's context.
let span = debug_span!("accept", client.addr = %addrs.param()).entered();
let Remote(ClientAddr(client_addr)) = addrs.param();
let span = debug_span!("accept", client.addr = %client_addr).entered();
let accept = new_accept.new_service(addrs);

// Dispatch all of the work for a given connection onto a
Expand All @@ -57,15 +58,17 @@ pub async fn serve<M, S, I, A>(
Err(reason) if is_io(&*reason) => {
debug!(%reason, "Connection closed")
}
Err(error) => info!(%error, "Connection closed"),
Err(error) => {
info!(%error, client.addr = %client_addr, "Connection closed")
}
}
// Hold the service until the connection is complete. This
// helps tie any inner cache lifetimes to the services they
// return.
drop(accept);
}
Err(error) => {
warn!(%error, "Server failed to become ready");
warn!(%error, client.addr = %client_addr, "Server failed to become ready");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions linkerd/proxy/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ futures = { version = "0.3", default-features = false }
linkerd-io = { path = "../../io" }
linkerd-stack = { path = "../../stack" }
socket2 = "0.4"
thiserror = "1"
tokio = { version = "1", features = ["macros", "net"] }
tokio-stream = { version = "0.1", features = ["net"] }
tracing = "0.1.29"
Expand Down
23 changes: 20 additions & 3 deletions linkerd/proxy/transport/src/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use futures::prelude::*;
use linkerd_io as io;
use linkerd_stack::Param;
use std::{fmt, pin::Pin};
use thiserror::Error;
use tokio::net::TcpStream;
use tokio_stream::wrappers::TcpListenerStream;

Expand Down Expand Up @@ -37,6 +38,18 @@ pub struct Addrs {
pub client: Remote<ClientAddr>,
}

#[derive(Debug, Error)]
#[error("failed to accept socket: {0}")]
struct AcceptError(#[source] io::Error);

#[derive(Debug, Error)]
#[error("failed to set TCP keepalive: {0}")]
struct KeepaliveError(#[source] io::Error);

#[derive(Debug, Error)]
#[error("failed to obtain peer address: {0}")]
struct PeerAddrError(#[source] io::Error);

// === impl BindTcp ===

impl BindTcp {
Expand Down Expand Up @@ -64,10 +77,14 @@ where
let server = Local(ServerAddr(listen.local_addr()?));
let Keepalive(keepalive) = params.param();
let accept = TcpListenerStream::new(listen).map(move |res| {
let tcp = res?;
let tcp = res.map_err(|e| io::Error::new(e.kind(), AcceptError(e)))?;
super::set_nodelay_or_warn(&tcp);
let tcp = super::set_keepalive_or_warn(tcp, keepalive)?;
let client = Remote(ClientAddr(tcp.peer_addr()?));
let tcp = super::set_keepalive_or_warn(tcp, keepalive)
.map_err(|e| io::Error::new(e.kind(), KeepaliveError(e)))?;
let client = Remote(ClientAddr(
tcp.peer_addr()
.map_err(|e| io::Error::new(e.kind(), PeerAddrError(e)))?,
olix0r marked this conversation as resolved.
Show resolved Hide resolved
));
Ok((Addrs { server, client }, tcp))
});

Expand Down