From b516290b7714ced677a182a26633fd8bf98a9b57 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Tue, 29 Sep 2020 09:02:38 -0700 Subject: [PATCH] [dbwriter] exponential backoff wait for server start Summary: When using the database write server process, the parent has to wait for it to fully start up before continuing. Instead of dying after a fixed amount of time, never terminate (external timeouts can take care of that) and use exponential backoff to avoid spamming. Reviewed By: jvillard Differential Revision: D23989959 fbshipit-source-id: ff5232c14 --- infer/src/base/DBWriter.ml | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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