Skip to content

Commit 110fff5

Browse files
RCasattaafilini
authored andcommitted
remove from waiting_map also in case of errors
1 parent f9b318c commit 110fff5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/raw_client.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,15 @@ impl<S: Read + Write> RawClient<S> {
400400

401401
self.increment_calls();
402402

403-
let mut resp = self.recv(&receiver, req.id)?;
403+
let mut resp = match self.recv(&receiver, req.id) {
404+
Ok(resp) => resp,
405+
e @ Err(_) => {
406+
// In case of error our sender could still be left in the map, depending on where
407+
// the error happened. Just in case, try to remove it here
408+
self.waiting_map.lock().unwrap().remove(&req.id);
409+
return e;
410+
}
411+
};
404412
Ok(resp["result"].take())
405413
}
406414

@@ -505,7 +513,21 @@ impl<T: Read + Write> ElectrumApi for RawClient<T> {
505513
self.increment_calls();
506514

507515
while !missing_responses.is_empty() {
508-
let resp = self.recv(&receiver, *missing_responses.iter().nth(0).unwrap())?;
516+
let req_id = *missing_responses.iter().nth(0).unwrap();
517+
let resp = match self.recv(&receiver, req_id) {
518+
Ok(resp) => resp,
519+
Err(e) => {
520+
// In case of error our sender could still be left in the map, depending on where
521+
// the error happened. Just in case, try to remove it here
522+
warn!("got error for req_id {}: {:?}", req_id, e);
523+
warn!("removing all waiting req of this batch");
524+
let mut guard = self.waiting_map.lock().unwrap();
525+
for req_id in missing_responses.iter() {
526+
guard.remove(&req_id);
527+
}
528+
return Err(e);
529+
}
530+
};
509531
let resp_id = resp["id"].as_u64().unwrap() as usize;
510532

511533
missing_responses.remove(&resp_id);

0 commit comments

Comments
 (0)