You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ocaml/database/block_device_io.ml
+37-32Lines changed: 37 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -306,38 +306,43 @@ let accept_conn s latest_response_time =
306
306
(* Listen on a given socket. Accept a single connection and transfer all the data from it to dest_fd, or raise Timeout if target_response_time happens first. *)
307
307
(* Raises NotEnoughSpace if the next write would exceed the available_space. *)
let data_client = accept_conn s target_response_time in
312
-
R.info "Accepted connection on data socket";
313
-
ignore_exn (fun() -> Unix.close s);
314
-
315
-
(* Read all the data from the data channel, writing it straight into the block device, keeping track of accumulated length *)
316
-
let total_length =ref0in
317
-
R.debug "Reading from data socket, writing to the block device...";
318
-
let bytes_read = finally
319
-
(fun() ->
320
-
(* Read data from the client until EOF. Returns the length read. *)
321
-
Unixext.read_data_in_chunks (funchunklen ->
322
-
(* Check that there's enough space *)
323
-
if available_space -!total_length < len then raise NotEnoughSpace;
324
-
(* Otherwise write it *)
325
-
Unixext.time_limited_write dest_fd len chunk target_response_time;
326
-
total_length :=!total_length + len
327
-
) ~block_size:16384 data_client
328
-
)
329
-
(fun() ->
330
-
(* Close the connection *)
331
-
(* CA-42914: If there was an exception, note that we are forcibly closing the connection when possibly the client (xapi) is still trying to write data. This will cause it to see a 'connection reset by peer' error. *)
332
-
R.info "Closing connection on data socket";
333
-
try
334
-
Unix.shutdown data_client Unix.SHUTDOWN_ALL;
335
-
Unix.close data_client
336
-
withe ->
337
-
R.warn "Exception %s while closing socket" (Printexc.to_string e);
338
-
) in
339
-
R.debug "Finished reading from data socket";
340
-
bytes_read
309
+
(* Open the data channel *)
310
+
let s = listen_on sock in
311
+
try
312
+
(* May raise a Timeout exception: CA-106403 *)
313
+
let data_client = accept_conn s target_response_time in
314
+
R.info "Accepted connection on data socket";
315
+
ignore_exn (fun() -> Unix.close s);
316
+
317
+
(* Read all the data from the data channel, writing it straight into the block device, keeping track of accumulated length *)
318
+
let total_length =ref0in
319
+
R.debug "Reading from data socket, writing to the block device...";
320
+
let bytes_read = finally
321
+
(fun() ->
322
+
(* Read data from the client until EOF. Returns the length read. *)
323
+
Unixext.read_data_in_chunks (funchunklen ->
324
+
(* Check that there's enough space *)
325
+
if available_space -!total_length < len then raise NotEnoughSpace;
326
+
(* Otherwise write it *)
327
+
Unixext.time_limited_write dest_fd len chunk target_response_time;
328
+
total_length :=!total_length + len
329
+
) ~block_size:16384 data_client
330
+
)
331
+
(fun() ->
332
+
(* Close the connection *)
333
+
(* CA-42914: If there was an exception, note that we are forcibly closing the connection when possibly the client (xapi) is still trying to write data. This will cause it to see a 'connection reset by peer' error. *)
334
+
R.info "Closing connection on data socket";
335
+
try
336
+
Unix.shutdown data_client Unix.SHUTDOWN_ALL;
337
+
Unix.close data_client
338
+
withe ->
339
+
R.warn "Exception %s while closing socket" (Printexc.to_string e);
0 commit comments