From 3da1e56133e74445e6d49942ade65413e053f7ee Mon Sep 17 00:00:00 2001 From: Pierre Chambart Date: Tue, 26 Jun 2018 19:58:40 +0200 Subject: [PATCH] Shell: Avoid leak in distributed_db_functor worker loop --- src/lib_shell/distributed_db_functors.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib_shell/distributed_db_functors.ml b/src/lib_shell/distributed_db_functors.ml index e75a5621b..230bf9f8b 100644 --- a/src/lib_shell/distributed_db_functors.ml +++ b/src/lib_shell/distributed_db_functors.ml @@ -466,9 +466,10 @@ end = struct (* TODO *) Lwt.return_unit - let rec worker_loop state = - let shutdown = Lwt_canceler.cancelation state.canceler - and timeout = compute_timeout state in + let worker_loop state = + let shutdown = Lwt_canceler.cancelation state.canceler in + let rec loop state = + let timeout = compute_timeout state in Lwt.choose [ (state.events >|= fun _ -> ()) ; timeout ; shutdown ] >>= fun () -> if Lwt.state shutdown <> Lwt.Sleep then @@ -479,7 +480,7 @@ end = struct state.events >>= fun events -> state.events <- Lwt_pipe.pop_all state.queue ; Lwt_list.iter_s (process_event state now) events >>= fun () -> - worker_loop state + loop state else lwt_debug "timeout" >>= fun () -> let now = Unix.gettimeofday () in @@ -518,7 +519,9 @@ end = struct Hash.pp key P2p_peer.Id.pp_short peer) request end requests Lwt.return_unit >>= fun () -> - worker_loop state + loop state + in + loop state let create param = let state = {