Procházet zdrojové kódy

rpc/rpcclient: catch the error when send to closed channel

ghassmo před 4 roky
rodič
revize
45382ecb74
1 změnil soubory, kde provedl 8 přidání a 1 odebrání
  1. 8 1
      src/rpc/rpcclient.rs

+ 8 - 1
src/rpc/rpcclient.rs

@@ -27,7 +27,14 @@ impl RpcClient {
         let req_id = value.id.clone().as_u64().unwrap_or(0);
         let req_id = value.id.clone().as_u64().unwrap_or(0);
         let value = json!(value);
         let value = json!(value);
 
 
-        self.sender.send(value).await?;
+        // TODO proper error handling for closed channels
+        // if the connection is closed the sender will get an error
+        // for sending to closed channel
+        let result = self.sender.send(value).await;
+        if result.is_err() {
+            error!("Unable to connect to the RPC server");
+            return Err(Error::OperationFailed)
+        }
 
 
         let reply = self.receiver.recv().await;
         let reply = self.receiver.recv().await;