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

do not panic on loss of oneshot channel reciever #356

Merged
merged 1 commit into from
Mar 8, 2018
Merged
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
45 changes: 20 additions & 25 deletions proto/src/dns_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
// copied, modified, or distributed except according to those terms.

use std::borrow::Borrow;
use std::sync::Arc;
use std::collections::{HashMap, HashSet};
use std::fmt::Debug;
use std::io;
use std::marker::PhantomData;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};


Expand Down Expand Up @@ -73,6 +74,13 @@ where
}
}

/// Ignores the result of a send operation and logs and ignores errors
fn ignore_send<M, E: Debug>(result: Result<M, E>) {
if let Err(error) = result {
warn!("error notifying wait, possible future leak: {:?}", error);
}
}

/// A DNS Client implemented over futures-rs.
///
/// This Client is generic and capable of wrapping UDP, TCP, and other underlying DNS protocol
Expand Down Expand Up @@ -211,8 +219,7 @@ where
// then the otherside isn't really paying attention anyway)

// complete the request, it's failed...
req.send(Err(E::from(ProtoErrorKind::Timeout.into())))
.expect("error notifying wait, possible future leak");
ignore_send(req.send(Err(E::from(ProtoErrorKind::Timeout.into()))));
}
}
}
Expand Down Expand Up @@ -287,9 +294,7 @@ where
if let Some(ref signer) = self.signer {
if let Err(e) = message.finalize::<MF>(signer.borrow(), now) {
warn!("could not sign message: {}", e);
complete
.send(Err(e.into()))
.expect("error notifying wait, possible future leak");
ignore_send(complete.send(Err(e.into())));
continue; // to the next message...
}
}
Expand All @@ -300,9 +305,7 @@ where
Ok(timeout) => timeout,
Err(e) => {
warn!("could not create timer: {}", e);
complete
.send(Err(E::from(e.into())))
.expect("error notifying wait, possible future leak");
ignore_send(complete.send(Err(E::from(e.into()))));
continue; // to the next message...
}
};
Expand All @@ -320,9 +323,7 @@ where
Err(e) => {
debug!("error message id: {} error: {}", query_id, e);
// complete with the error, don't add to the map of active requests
complete
.send(Err(e.into()))
.expect("error notifying wait, possible future leak");
ignore_send(complete.send(Err(e.into())));
}
}
}
Expand All @@ -346,9 +347,7 @@ where
// deserialize or log decode_error
match Message::from_vec(&buffer) {
Ok(message) => match self.active_requests.remove(&message.id()) {
Some((complete, _)) => complete
.send(Ok(message))
.expect("error notifying wait, possible future leak"),
Some((complete, _)) => ignore_send(complete.send(Ok(message))),
None => debug!("unexpected request_id: {}", message.id()),
},
// TODO: return src address for diagnostics
Expand Down Expand Up @@ -404,11 +403,9 @@ where
fn poll(&mut self) -> Poll<(), Self::Error> {
match self.new_receiver.poll() {
Ok(Async::Ready(Some((_, complete)))) => {
complete
.send(Err(
E::from(ProtoErrorKind::Msg(self.error_msg.clone()).into()),
))
.expect("error notifying wait, possible future leak");
ignore_send(complete.send(Err(
E::from(ProtoErrorKind::Msg(self.error_msg.clone()).into()),
)));

task::current().notify();
Ok(Async::NotReady)
Expand Down Expand Up @@ -470,11 +467,9 @@ where
Ok(()) => receiver,
Err(e) => {
let (complete, receiver) = oneshot::channel();
complete
.send(Err(E::from(
ProtoErrorKind::Msg(format!("error sending to channel: {}", e)).into(),
)))
.expect("error notifying wait, possible future leak");
ignore_send(complete.send(Err(E::from(
ProtoErrorKind::Msg(format!("error sending to channel: {}", e)).into(),
))));
receiver
}
};
Expand Down