From cbfe8f749904be88c1c2e9b8e3abe0c279a86e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thir=C3=A9?= Date: Mon, 3 Apr 2023 12:15:48 +0200 Subject: [PATCH] Shell/Chain_validator: The disconnection is asynchronous --- src/lib_shell/chain_validator.ml | 9 +++++++++ src/lib_shell/peer_validator.ml | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/lib_shell/chain_validator.ml b/src/lib_shell/chain_validator.ml index bfd8c36b0344..6f8ece6a9010 100644 --- a/src/lib_shell/chain_validator.ml +++ b/src/lib_shell/chain_validator.ml @@ -613,6 +613,15 @@ let on_disconnection w peer_id = let*! pv in match pv with | Ok pv -> + (* Shutting down the peer validator will indirectly trigger + a disconnection. However, the disconnection can be + effective only after the peer validator is shutdown (see + {!val:Peer_validator.on_close}). This is a defensive + mechanism so that if the disconnection takes too much + time (even though it is not supposed to happen), the + validation is not stuck. In any case, the peer validator + is removed from the active peers (see + {!val:with_activated_peer_validator}). *) let*! () = Peer_validator.shutdown pv in return_unit) diff --git a/src/lib_shell/peer_validator.ml b/src/lib_shell/peer_validator.ml index 82f1d6e03ee1..1a20e287a39a 100644 --- a/src/lib_shell/peer_validator.ml +++ b/src/lib_shell/peer_validator.ml @@ -451,9 +451,17 @@ let on_error (type a b) w st (request : (a, b) Request.t) (err : b) : | New_branch _ -> on_error_trace err let on_close w = - let open Lwt_syntax in let pv = Worker.state w in - let* () = Distributed_db.disconnect pv.parameters.chain_db pv.peer_id in + (* We request the the P2P layer to disconnect from this peer, but we + do not wait for the disconnection to be effective (the underlying + socket is closed). This is because the P2P layer does not offer + the guarantee that the disconnection will be quick. + + This is not a problem, and allows the reconnection with this peer + using a different socket. *) + let (_ : unit Lwt.t) = + Distributed_db.disconnect pv.parameters.chain_db pv.peer_id + in pv.parameters.notify_termination () ; Lwt.return_unit -- GitLab