From a1f0ea770e86bcfa765d01cddb74f05ec327f902 Mon Sep 17 00:00:00 2001 From: "iguerNL@Functori" Date: Mon, 9 Dec 2024 08:52:47 +0100 Subject: [PATCH] Octez-p2p: set SO_KEEPALIVE to true for connections --- src/lib_p2p/p2p_fd.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib_p2p/p2p_fd.ml b/src/lib_p2p/p2p_fd.ml index 6ca4160a7a6d..56f39eadff06 100644 --- a/src/lib_p2p/p2p_fd.ml +++ b/src/lib_p2p/p2p_fd.ml @@ -170,6 +170,14 @@ let create_listening_socket ?(reuse_port = false) ~backlog let sock = raw_socket () in (if reuse_port then Lwt_unix.(setsockopt sock SO_REUSEPORT true)) ; Lwt_unix.(setsockopt sock SO_REUSEADDR true) ; + + (* By setting [SO_KEEPALIVE] to [true], the socket is configured to send + periodic keep-alive probes to verify that the connection is still + active. + + It reset (send TCP RST message and close) if the peer is + unresponsive. *) + Lwt_unix.(setsockopt sock SO_KEEPALIVE true) ; let*! () = Lwt_unix.bind sock -- GitLab