From 8f4ba32b58a1eb51e2736b09ecb1f6c3d4167cd8 Mon Sep 17 00:00:00 2001 From: "Y. T. Chung" Date: Fri, 18 May 2018 22:32:57 +0800 Subject: [PATCH] Updated join_all in DNS relay, enable backtrace in appveyor --- appveyor.yml | 3 ++- src/relay/udprelay/dns.rs | 27 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 0f0af336..5f746f41 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,6 +8,7 @@ environment: MSYS2: 1 OPENSSL_DIR: C:\OpenSSL SODIUM_BUILD_STATIC: yes + RUST_BACKTRACE: 1 # - TARGET: i686-pc-windows-gnu # BITS: 32 # OPENSSL_VERSION: 1_1_0g @@ -30,7 +31,7 @@ install: build: false test_script: - - cargo test -v --no-fail-fast + - cargo test --no-fail-fast cache: - target diff --git a/src/relay/udprelay/dns.rs b/src/relay/udprelay/dns.rs index 80442866..995e8fd3 100644 --- a/src/relay/udprelay/dns.rs +++ b/src/relay/udprelay/dns.rs @@ -8,11 +8,11 @@ use std::time::Instant; use dns_parser::{Packet, RRData}; use futures::future::join_all; +use futures::stream::futures_unordered; use futures::{self, Future, Stream}; use lru_cache::LruCache; use tokio; use tokio::net::UdpSocket; -use tokio_io::IoFuture; use super::crypto_io::{decrypt_payload, encrypt_payload}; use super::{PacketStream, SendDgramRc, SharedUdpSocket}; @@ -121,16 +121,14 @@ impl<'a> fmt::Display for PrettyPacket<'a> { } /// Starts a UDP DNS server -pub fn run(config: Arc) -> IoFuture<()> { +pub fn run(config: Arc) -> impl Future + Send { let local_addr = *config.local.as_ref().unwrap(); - let fut = futures::lazy(move || { - info!("ShadowSocks UDP DNS Listening on {}", local_addr); + futures::lazy(move || { + info!("ShadowSocks UDP DNS Listening on {}", local_addr); - UdpSocket::bind(&local_addr) - }).and_then(move |l| listen(config, l)); - - boxed_future(fut) + UdpSocket::bind(&local_addr) + }).and_then(move |l| listen(config, l)) } fn listen(config: Arc, l: UdpSocket) -> impl Future + Send { @@ -166,9 +164,18 @@ fn listen(config: Arc, l: UdpSocket) -> impl Future { + error!("One of DNS servers exited unexpectly without error"); + let err = io::Error::new(io::ErrorKind::Other, "server exited unexpectly"); + Err(err) + } + Err((err, ..)) => { + error!("One of DNS servers exited unexpectly with error {}", err); + Err(err) + } + }) }) - .map(|_| ()) } lazy_static! {