Skip to content

Commit ef3ddfd

Browse files
committed
Pass Arc<io::Error> to waiting threads
1 parent f200b7f commit ef3ddfd

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/raw_client.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::mem::drop;
88
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
99
use std::sync::atomic::{AtomicUsize, Ordering};
1010
use std::sync::mpsc::{channel, Receiver, Sender};
11-
use std::sync::{Mutex, TryLockError};
11+
use std::sync::{Arc, Mutex, TryLockError};
1212
use std::time::Duration;
1313

1414
#[allow(unused_imports)]
@@ -352,7 +352,7 @@ impl RawClient<ElectrumProxyStream> {
352352
enum ChannelMessage {
353353
Response(serde_json::Value),
354354
WakeUp,
355-
Error,
355+
Error(Arc<std::io::Error>),
356356
}
357357

358358
impl<S: Read + Write> RawClient<S> {
@@ -398,9 +398,10 @@ impl<S: Read + Write> RawClient<S> {
398398
loop {
399399
raw_resp.clear();
400400

401-
if reader.read_line(&mut raw_resp).is_err() {
401+
if let Err(e) = reader.read_line(&mut raw_resp) {
402+
let error = Arc::new(e);
402403
for (_, s) in self.waiting_map.lock().unwrap().drain() {
403-
s.send(ChannelMessage::Error)
404+
s.send(ChannelMessage::Error(error.clone()))
404405
.expect("Unable to send ChannelMessage::Error");
405406
}
406407
}
@@ -531,10 +532,10 @@ impl<S: Read + Write> RawClient<S> {
531532

532533
continue;
533534
}
534-
Ok(ChannelMessage::Error) => {
535+
Ok(ChannelMessage::Error(e)) => {
535536
warn!("Received ChannelMessage::Error");
536537

537-
break Err(Error::ChannelError);
538+
break Err(Error::ChannelError(e));
538539
}
539540
e @ Err(_) => e.map(|_| ()).expect("Error receiving from channel"), // panic if there's something wrong with the channels
540541
}

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use std::convert::TryFrom;
66
use std::ops::Deref;
7+
use std::sync::Arc;
78

89
use bitcoin::blockdata::block;
910
use bitcoin::consensus::encode::deserialize;
@@ -291,7 +292,7 @@ pub enum Error {
291292
/// Made one or multiple attempts, always in Error
292293
AllAttemptsErrored(Vec<Error>),
293294
/// There was an error transmitted from the reader thread to others
294-
ChannelError,
295+
ChannelError(Arc<std::io::Error>),
295296
/// Setting both a proxy and a timeout in `Config` results in this error
296297
BothSocksAndTimeout,
297298
/// Setting both a timeout and passing zero or more than one socket addrs is an error

0 commit comments

Comments
 (0)