From b7c2546e5b220e016d1f99791397f56033682cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Tue, 5 Mar 2019 17:29:09 +0100 Subject: [PATCH] Daemon: `await_bootstrapped_node` now retries on `Connection_failed` This allows the baker/endorser/accuser to wait a litlle bit for the node to initialize itself and to open its RPC port. By default, the deamon retries 6 times with a total waiting time around 20 seconds, before to fail. --- src/proto_alpha/lib_delegate/client_daemon.ml | 24 ++++++++++++++++++- src/proto_alpha/lib_delegate/dune | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_delegate/client_daemon.ml b/src/proto_alpha/lib_delegate/client_daemon.ml index 54ed9c3ee..cf17838c6 100644 --- a/src/proto_alpha/lib_delegate/client_daemon.ml +++ b/src/proto_alpha/lib_delegate/client_daemon.ml @@ -23,11 +23,33 @@ (* *) (*****************************************************************************) +let rec retry (cctxt: #Proto_alpha.full) ~delay ~tries f x = + f x >>= function + | Ok _ as r -> Lwt.return r + | Error (RPC_client.Request_failed + { error = Connection_failed _ ; _ } :: _) as err + when tries > 0 -> begin + cctxt#message + "Connection refused, retrying in %.2f seconds..." + delay >>= fun () -> + Lwt.pick + [ (Lwt_unix.sleep delay >|= fun () -> `Continue) ; + (Lwt_exit.termination_thread >|= fun _ -> `Killed) ; + ] >>= function + | `Killed -> + Lwt.return err + | `Continue -> + retry cctxt ~delay:(delay *. 1.5) ~tries:(tries - 1) f x + end + | Error _ as err -> + Lwt.return err + let await_bootstrapped_node (cctxt: #Proto_alpha.full) = (* Waiting for the node to be synchronized *) cctxt#message "Waiting for the node to be synchronized with its \ peers..." >>= fun () -> - Shell_services.Monitor.bootstrapped cctxt >>=? fun _ -> + retry cctxt ~tries:5 ~delay:1. + Shell_services.Monitor.bootstrapped cctxt >>=? fun _ -> cctxt#message "Node synchronized." >>= fun () -> return_unit diff --git a/src/proto_alpha/lib_delegate/dune b/src/proto_alpha/lib_delegate/dune index 6de77c06d..bb3ed553b 100644 --- a/src/proto_alpha/lib_delegate/dune +++ b/src/proto_alpha/lib_delegate/dune @@ -9,6 +9,7 @@ tezos-client-alpha tezos-client-commands tezos-storage + tezos-rpc-http tezos-rpc) (library_flags (:standard -linkall)) (modules (:standard \ @@ -22,7 +23,8 @@ -open Tezos_client_alpha -open Tezos_client_commands -open Tezos_storage - -open Tezos_rpc))) + -open Tezos_rpc + -open Tezos_rpc_http))) (library (name tezos_baking_alpha_commands)