Skip to content

Commit

Permalink
improve error for dns getaddrinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
meowjesty committed Oct 15, 2024
1 parent 1cf71f3 commit 11da23c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
8 changes: 6 additions & 2 deletions mirrord/agent/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl DnsWorker {
let hosts_path = etc_path.join("hosts");

// TODO(alex) [high] 1: Return an io error here so we can inspect it in mirrord.
let resolv_conf = fs::read(resolv_conf_path).await?;
let resolv_conf = fs::read("/meow/meow").await?;
let hosts_conf = fs::read(hosts_path).await?;

let (config, mut options) = parse_resolv_conf(resolv_conf)?;
Expand All @@ -112,12 +112,16 @@ impl DnsWorker {
}

/// Handles the given [`DnsCommand`] in a separate [`tokio::task`].
#[tracing::instrument(level = Level::DEBUG, skip(self))]
fn handle_message(&self, message: DnsCommand) {
let etc_path = self.etc_path.clone();
let timeout = self.timeout;
let attempts = self.attempts;
let lookup_future = async move {
let result = Self::do_lookup(etc_path, message.request.node, attempts, timeout).await;
let result = Self::do_lookup(etc_path, message.request.node, attempts, timeout)
.await
.inspect_err(|fail| tracing::error!(?fail, "DNS lookup failed!"));
tracing::debug!(?result, "DNS RESULT!");
if let Err(result) = message.response_tx.send(result) {
tracing::error!(?result, "Failed to send query response");
}
Expand Down
4 changes: 2 additions & 2 deletions mirrord/layer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use mirrord_protocol::{ResponseError, SerializationError};
#[cfg(target_os = "macos")]
use mirrord_sip::SipError;
use thiserror::Error;
use tracing::{error, info};
use tracing::{error, info, Level};

Check warning on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / integration_tests

unused import: `Level`

Check failure on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / integration_tests

unused import: `Level`

Check failure on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / check-rust-docs

unused import: `Level`

Check failure on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / lint

unused import: `Level`

Check failure on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / macos_tests

unused import: `Level`

Check warning on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / e2e (docker)

unused import: `Level`

Check warning on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / e2e (docker)

unused import: `Level`

Check warning on line 11 in mirrord/layer/src/error.rs

View workflow job for this annotation

GitHub Actions / e2e (containerd)

unused import: `Level`

use crate::{graceful_exit, proxy_connection::ProxyError};

Expand Down Expand Up @@ -41,7 +41,7 @@ mod ignore_codes {
/// These errors are converted to [`libc`] error codes, and are also used to [`set_errno`].
#[derive(Error, Debug)]
pub(crate) enum HookError {
#[error("mirrord-layer: Failed while getting a response!")]
#[error(transparent)]
ResponseError(#[from] ResponseError),

#[error("mirrord-layer: DNS does not resolve!")]
Expand Down
2 changes: 1 addition & 1 deletion mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ pub(super) fn dup<const SWITCH_MAP: bool>(fd: c_int, dup_fd: i32) -> Result<(),
/// # Note
///
/// This function updates the mapping in [`REMOTE_DNS_REVERSE_MAPPING`].
#[mirrord_layer_macro::instrument(level = Level::TRACE, ret)]
#[mirrord_layer_macro::instrument(level = Level::DEBUG, ret, err)]
pub(super) fn remote_getaddrinfo(node: String) -> HookResult<Vec<(String, IpAddr)>> {
let addr_info_list = common::make_proxy_request_with_response(GetAddrInfoRequest { node })?.0?;

Expand Down
19 changes: 16 additions & 3 deletions mirrord/protocol/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use bincode::{Decode, Encode};
use hickory_resolver::error::{ResolveError, ResolveErrorKind};
use thiserror::Error;
use tracing::warn;
use tracing::{warn, Level};

use crate::{
outgoing::SocketAddress,
Expand Down Expand Up @@ -44,7 +44,7 @@ pub enum ResponseError {
#[error("IO failed for remote operation with `{0}!")]
RemoteIO(RemoteIOError),

#[error("IO failed for remote operation with `{0}!")]
#[error(transparent)]
DnsLookup(DnsLookupError),

#[error("Remote operation failed with `{0}`")]
Expand Down Expand Up @@ -158,6 +158,7 @@ pub struct DnsLookupError {
}

impl From<io::Error> for ResponseError {
#[tracing::instrument(level = Level::DEBUG, ret)]
fn from(io_error: io::Error) -> Self {
Self::RemoteIO(RemoteIOError {
raw_os_error: io_error.raw_os_error(),
Expand All @@ -167,6 +168,7 @@ impl From<io::Error> for ResponseError {
}

impl From<ResolveError> for ResponseError {
#[tracing::instrument(level = Level::DEBUG, ret)]
fn from(fail: ResolveError) -> Self {
match fail.kind().to_owned() {
ResolveErrorKind::Io(io_fail) => io_fail.into(),
Expand Down Expand Up @@ -233,6 +235,8 @@ pub enum ResolveErrorKindInternal {
Timeout,
// Unknown is for uncovered cases (enum is non-exhaustive)
Unknown,
NotFound,
PermissionDenied,
}

impl From<io::ErrorKind> for ErrorKindInternal {
Expand Down Expand Up @@ -285,6 +289,7 @@ impl From<io::ErrorKind> for ErrorKindInternal {

impl From<ResolveErrorKind> for ResolveErrorKindInternal {
fn from(error_kind: ResolveErrorKind) -> Self {
println!("{error_kind:?}");
match error_kind {
ResolveErrorKind::Message(message) => {
ResolveErrorKindInternal::Message(message.to_string())
Expand All @@ -296,8 +301,16 @@ impl From<ResolveErrorKind> for ResolveErrorKindInternal {
}
ResolveErrorKind::Proto(_) => ResolveErrorKindInternal::Proto,
ResolveErrorKind::Timeout => ResolveErrorKindInternal::Timeout,
ResolveErrorKind::Io(fail) => match fail.kind() {
io::ErrorKind::NotFound => ResolveErrorKindInternal::NotFound,
io::ErrorKind::PermissionDenied => ResolveErrorKindInternal::PermissionDenied,
other => {
warn!(?other, "unknown IO error");
ResolveErrorKindInternal::Unknown
}
},
_ => {
warn!("unknown error kind: {:?}", error_kind);
warn!(?error_kind, "unknown error kind");
ResolveErrorKindInternal::Unknown
}
}
Expand Down

0 comments on commit 11da23c

Please sign in to comment.