diff --git a/src/raw_client.rs b/src/raw_client.rs index c7c7ae2..78f943a 100644 --- a/src/raw_client.rs +++ b/src/raw_client.rs @@ -8,7 +8,7 @@ use std::mem::drop; use std::net::{SocketAddr, TcpStream, ToSocketAddrs}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::{channel, Receiver, Sender}; -use std::sync::{Mutex, TryLockError}; +use std::sync::{Arc, Mutex, TryLockError}; use std::time::Duration; #[allow(unused_imports)] @@ -352,7 +352,7 @@ impl RawClient { enum ChannelMessage { Response(serde_json::Value), WakeUp, - Error, + Error(Arc), } impl RawClient { @@ -398,9 +398,10 @@ impl RawClient { loop { raw_resp.clear(); - if reader.read_line(&mut raw_resp).is_err() { + if let Err(e) = reader.read_line(&mut raw_resp) { + let error = Arc::new(e); for (_, s) in self.waiting_map.lock().unwrap().drain() { - s.send(ChannelMessage::Error) + s.send(ChannelMessage::Error(error.clone())) .expect("Unable to send ChannelMessage::Error"); } } @@ -531,10 +532,10 @@ impl RawClient { continue; } - Ok(ChannelMessage::Error) => { + Ok(ChannelMessage::Error(e)) => { warn!("Received ChannelMessage::Error"); - break Err(Error::ChannelError); + break Err(Error::ChannelError(e)); } e @ Err(_) => e.map(|_| ()).expect("Error receiving from channel"), // panic if there's something wrong with the channels } diff --git a/src/types.rs b/src/types.rs index af0dcac..e24251c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -4,6 +4,7 @@ use std::convert::TryFrom; use std::ops::Deref; +use std::sync::Arc; use bitcoin::blockdata::block; use bitcoin::consensus::encode::deserialize; @@ -291,7 +292,7 @@ pub enum Error { /// Made one or multiple attempts, always in Error AllAttemptsErrored(Vec), /// There was an error transmitted from the reader thread to others - ChannelError, + ChannelError(Arc), /// Setting both a proxy and a timeout in `Config` results in this error BothSocksAndTimeout, /// Setting both a timeout and passing zero or more than one socket addrs is an error