diff --git a/CHANGES.rst b/CHANGES.rst index 6e5bca5bc4f29a93d7ccde48360212ebc0ccb2ed..aec9ab6fb2ea5fc14c53d1d3739c2e6ac08e51a6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -256,6 +256,10 @@ Data Availability Layer (DAL) DAL node ~~~~~~~~ +- **Bugfix** From v21.2, the ``SO_KEEP_ALIVE`` socket option was used + for incoming connections only. It is not used with both incoming + connections and outgoing connections. + - **Bugfix** From v21.2, the DAL node tries to recontact peers after the connection attempt failed. However, this MR fixes the timing when those attempts were made (MR :gl:`!16466`) diff --git a/src/lib_p2p/p2p_fd.ml b/src/lib_p2p/p2p_fd.ml index a83a76604f474b3f39738ccf0ddc598cb14edd40..2339af69377b03be1eaee3672fc4806c8a4493fd 100644 --- a/src/lib_p2p/p2p_fd.ml +++ b/src/lib_p2p/p2p_fd.ml @@ -163,7 +163,16 @@ let string_of_sockaddr addr = let id t = t.id -let raw_socket () = Lwt_unix.socket ~cloexec:true PF_INET6 SOCK_STREAM 0 +let raw_socket () = + let sock = Lwt_unix.socket ~cloexec:true PF_INET6 SOCK_STREAM 0 in + (* 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) ; + sock let socket () = create (raw_socket ()) @@ -175,14 +184,6 @@ 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