Skip to content

Commit

Permalink
resolver: try TCP on InvalidData errors
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed May 1, 2024
1 parent 6cfecb1 commit eeebd84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions crates/proto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ impl ProtoError {
matches!(*self.kind, ProtoErrorKind::NoConnections)
}

/// Returns the `io::ErrorKind` if this is an IO error
pub fn io_kind(&self) -> Option<io::ErrorKind> {
match self.kind() {
ProtoErrorKind::Io(e) => Some(e.kind()),
_ => None,
}
}

pub(crate) fn as_dyn(&self) -> &(dyn std::error::Error + 'static) {
self
}
Expand Down
13 changes: 10 additions & 3 deletions crates/resolver/src/name_server/name_server_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// copied, modified, or distributed except according to those terms.

use std::cmp::Ordering;
use std::io;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -263,9 +264,15 @@ where
debug!("truncated response received, retrying over TCP");
Ok(response)
}
Err(e) if opts.try_tcp_on_error || e.is_no_connections() => {
debug!("error from UDP, retrying over TCP: {}", e);
Err(e)
Err(e) if opts.try_tcp_on_error => {
if e.is_no_connections()
|| matches!(e.io_kind(), Some(io::ErrorKind::InvalidData))
{
debug!("error from UDP, retrying over TCP: {e}");
Err(e)
} else {
return Err(ProtoError::from(e));
}
}
result => return result.map_err(ProtoError::from),
};
Expand Down

0 comments on commit eeebd84

Please sign in to comment.