]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
CA-42914: Catch other exceptions when reading commands from client in block_device_io
authorJonathan Davies <jonathan.davies@citrix.com>
Thu, 28 Oct 2010 16:00:42 +0000 (17:00 +0100)
committerJonathan Davies <jonathan.davies@citrix.com>
Thu, 28 Oct 2010 16:00:42 +0000 (17:00 +0100)
Previously, we only caught End_of_file which Unixext.really_read throws when the client sends EOF. Other exceptions dribbled through to the deeper exception handler, which was supposed to be reserved exclusively for problems opening the block device.

Now, we also catch other exceptions in the same place as the End_of_file exception is handled.

Signed-off-by: Jonathan Davies <jonathan.davies@citrix.com>
ocaml/database/block_device_io.ml

index 9643455876d91c349dad7a7156a60a63bc7ddef6..26a88d2fa1dda0d0e8a41919fd74686e76538007 100644 (file)
@@ -784,15 +784,21 @@ let _ =
                 let target_response_time = Unix.gettimeofday() +. Xapi_globs.redo_log_max_block_time in
                 (* Note: none of the action functions throw any exceptions; they report errors directly to the client. *)
                 let action_fn = match str with
-                | "writedelta" -> action_writedelta
-                | "writedb___" -> action_writedb
-                | "read______" -> action_read
-                | "empty_____" -> action_empty
-                | _ -> (fun _ _ _ _ -> send_failure client (str^"|nack") ("Unknown command "^str)) in
+                  | "writedelta" -> action_writedelta
+                  | "writedb___" -> action_writedb
+                  | "read______" -> action_read
+                  | "empty_____" -> action_empty
+                  | _ -> (fun _ _ _ _ -> send_failure client (str^"|nack") ("Unknown command "^str))
+                in
                 action_fn block_dev_fd client !datasock target_response_time
-              with End_of_file -> stop := true
+              with (* this must be an exception in Unixext.really_read because action_fn doesn't throw exceptions *)
+              | End_of_file ->
+                  R.info "The client sent EOF";
+                  stop := true
+              | e ->
+                  R.info "Unexpected error when trying to read from client: %s. Closing connection." (Printexc.to_string e);
+                  stop := true
             done;
-            (* The client sent EOF *)
             R.debug "Stopping.";
             ignore_exn (fun () -> Unix.close client)
           )
@@ -802,11 +808,11 @@ let _ =
           )
       with (* problems opening block device *)
       | Unix.Unix_error(a,b,c) ->
-        R.error "Unix error on %s (%s) [%s]" b (Unix.error_message a) c;
+        R.error "Unix error when opening block device: %s (%s) [%s]" b (Unix.error_message a) c;
         ignore_exn (fun () -> send_failure client connect_failure_mesg (Printf.sprintf "Unix error on %s (%s) [%s]" b (Unix.error_message a) c));
         ignore_exn (fun () -> Unix.close client)
       | e ->
-        R.error "Received exception: %s" (Printexc.to_string e);
+        R.error "Unexpected exception when opening block device: %s" (Printexc.to_string e);
         ignore_exn (fun () -> send_failure client connect_failure_mesg (Printexc.to_string e));
         ignore_exn (fun () -> Unix.close client)
     done