Parcourir la source

Reset the connection only when all previous commands succeeded.

Jing Yang il y a 5 ans
Parent
commit
97146550d1
1 fichiers modifiés avec 8 ajouts et 9 suppressions
  1. 8 9
      src/network.rs

+ 8 - 9
src/network.rs

@@ -204,6 +204,14 @@ impl Network {
         };
 
         if reply.is_ok() {
+            // Fail the RPC if the client has been disconnected.
+            if network.lock().dispatch(&rpc.client).is_err() {
+                let _ = rpc.reply_channel.send(Err(std::io::Error::new(
+                    std::io::ErrorKind::ConnectionReset,
+                    format!("Network connection has been reset."),
+                )));
+                return;
+            }
             // Random drop again.
             if !reliable
                 && thread_rng().gen_ratio(Self::DROP_RATE.0, Self::DROP_RATE.1)
@@ -231,15 +239,6 @@ impl Network {
             }
         }
 
-        // Fail the RPC if the client has been disconnected.
-        let reply = match network.lock().dispatch(&rpc.client) {
-            Ok(_) => reply,
-            Err(_e) => Err(std::io::Error::new(
-                std::io::ErrorKind::ConnectionReset,
-                format!("Network connection has been reset."),
-            )),
-        };
-
         if let Err(_e) = rpc.reply_channel.send(reply) {
             // TODO(ditsing): log and do nothing.
         }