diff --git a/src/lib_shell/chain_validator.ml b/src/lib_shell/chain_validator.ml index bfd8c36b0344f5c35d28f1f076bf54ceed89f425..6f8ece6a9010df9d8b722993cc571eb968defbcf 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 82f1d6e03ee145611f06bb04b7797c601bcb9042..1a20e287a39a20376ca8b8bfffba00e9f1d09242 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