Skip to content

Commit 14fd0c9

Browse files
committed
CA-226177: Fix premature termination of cli
When the CLI makes a TLS connection to a remote host as part of a command, there was code to monitor the stunnel process and exit early if the stunnel process died. There was a race, therefore, when a TLS connection terminiated correctly but the command hadn't finished processing on the control socket, for example, when uploading a VDI via a CLI on a slave. This commit removes the active monitoring of stunnel processes. Signed-off-by: Jon Ludlam <[email protected]>
1 parent bbe29f5 commit 14fd0c9

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

ocaml/xe-cli/newcli.ml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let ciphersuites = ref None
3636
let xedebug = ref false
3737
let xedebugonfail = ref false
3838

39-
let stunnel_process = ref None
39+
let stunnel_processes = ref []
4040
let debug_channel = ref None
4141
let debug_file = ref None
4242

@@ -246,7 +246,7 @@ let open_tcp_ssl server =
246246
let x = Stunnel.connect ~use_fork_exec_helper:false
247247
~write_to_log:(fun x -> debug "stunnel: %s\n%!" x)
248248
~extended_diagnosis:(!debug_file <> None) server port in
249-
if !stunnel_process = None then stunnel_process := Some x;
249+
stunnel_processes := x :: !stunnel_processes;
250250
Unix.in_channel_of_descr x.Stunnel.fd, Unix.out_channel_of_descr x.Stunnel.fd
251251

252252
let open_tcp server =
@@ -331,19 +331,7 @@ let main_loop ifd ofd =
331331
*)
332332
while (match Unix.select [ifd] [] [] 5.0 with
333333
| _ :: _, _, _ -> false
334-
| _ ->
335-
match !stunnel_process with
336-
| Some { Stunnel.pid = Stunnel.FEFork pid } -> begin
337-
match Forkhelpers.waitpid_nohang pid with
338-
| 0, _ -> true
339-
| i, e -> raise (Stunnel_exit (i, e))
340-
end
341-
| Some {Stunnel.pid = Stunnel.StdFork pid} -> begin
342-
match Unix.waitpid [Unix.WNOHANG] pid with
343-
| 0, _ -> true
344-
| i, e -> raise (Stunnel_exit (i, e))
345-
end
346-
| _ -> true) do ()
334+
| _ -> true) do ()
347335
done;
348336
let cmd =
349337
try unmarshal ifd
@@ -673,8 +661,7 @@ let main () =
673661
| Unix.WSTOPPED c -> "stopped by signal " ^ string_of_int c)
674662
| e ->
675663
error "Unhandled exception\n%s\n" (Printexc.to_string e) in
676-
begin match !stunnel_process with
677-
| Some p ->
664+
List.iter (fun p ->
678665
if Sys.file_exists p.Stunnel.logfile then
679666
begin
680667
if !exit_status <> 0 then
@@ -683,9 +670,7 @@ let main () =
683670
with e -> debug "%s\n" (Printexc.to_string e));
684671
try Unix.unlink p.Stunnel.logfile with _ -> ()
685672
end;
686-
Stunnel.disconnect ~wait:false ~force:true p
687-
| None -> ()
688-
end;
673+
Stunnel.disconnect ~wait:false ~force:true p) !stunnel_processes;
689674
begin match !debug_file, !debug_channel with
690675
| Some f, Some ch -> begin
691676
close_out ch;

0 commit comments

Comments
 (0)