diff --git a/infer/src/base/DBWriter.ml b/infer/src/base/DBWriter.ml index 2dba4d241..cd0df81b5 100644 --- a/infer/src/base/DBWriter.ml +++ b/infer/src/base/DBWriter.ml @@ -363,12 +363,16 @@ module Server = struct In_channel.close in_channel - let rec retry ~pred ~timeout count = - if count < 0 then false - else if pred () then true - else ( - Unix.nanosleep timeout |> ignore ; - retry ~pred ~timeout (count - 1) ) + (* wait for socket to appear with 0.1 sec timeout, doubling each time ; + choice of numbers is arbitrary *) + let initial_wait_for_socket_secs = 0.1 + + let rec wait_for_server_start ~wait_secs = + Unix.nanosleep wait_secs |> ignore ; + if not (socket_exists ()) then ( + let wait_secs = 2.0 *. wait_secs in + L.progress "Waiting for Sqlite write daemon to start (%f seconds)@\n" wait_secs ; + wait_for_server_start ~wait_secs ) let start () = @@ -377,10 +381,7 @@ module Server = struct ForkUtils.protect ~f:server () ; L.exit 0 | `In_the_parent _child_pid -> - (* wait for socket to appear, try 5 times, with a 0.1 sec timeout each time ; - choice of numbers is completely arbitrary *) - if not (retry ~pred:socket_exists ~timeout:0.1 5) then - L.die InternalError "Sqlite write daemon never started@." ; + wait_for_server_start ~wait_secs:initial_wait_for_socket_secs ; send Command.Handshake end