فهرست منبع

drk/rpc: handle initial client failure due to offline darkfid

skoupidi 9 ماه پیش
والد
کامیت
a8682b50c8
1فایلهای تغییر یافته به همراه7 افزوده شده و 5 حذف شده
  1. 7 5
      bin/drk/src/rpc.rs

+ 7 - 5
bin/drk/src/rpc.rs

@@ -582,13 +582,15 @@ impl Drk {
     ) -> Result<JsonValue> {
         let Some(ref rpc_client) = self.rpc_client else { return Err(Error::RpcClientStopped) };
         let mut lock = rpc_client.write().await;
-        let Some(ref client) = lock.client else { return Err(Error::RpcClientStopped) };
         let req = JsonRequest::new(method, params.clone());
 
-        // Execute request
-        if let Ok(rep) = client.request(req.clone()).await {
-            drop(lock);
-            return Ok(rep)
+        // Check the client is initialized
+        if let Some(ref client) = lock.client {
+            // Execute request
+            if let Ok(rep) = client.request(req.clone()).await {
+                drop(lock);
+                return Ok(rep);
+            }
         }
 
         // Reset the rpc client in case of an error and try again