From b9224ad70d3aa1f721daf6f293a0e38b577bafab Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 19 Feb 2015 04:51:27 -0800 Subject: [PATCH] git-daemon: set SO_KEEPALIVE on git-daemon connections This should prevent indefinite hanging when attempting to read from a connection that is no longer connected thus avoiding an accumulation of processes stuck in read. --- src/peek_packet.c | 6 ++++++ xinetd/git | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/peek_packet.c b/src/peek_packet.c index 60d0bd8..ca61963 100644 --- a/src/peek_packet.c +++ b/src/peek_packet.c @@ -61,6 +61,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include #include #include +#include #include /* Note that mod_reqtimeout has a default configuration of 20 seconds @@ -116,12 +117,17 @@ int main(int argc, char *argv[]) char hexlen[4]; size_t pktlen; const char *nullptr; + int optval; (void)argc; (void)argv; expiry = time(NULL) + TIMEOUT_SECS; + optval = 1; + if (setsockopt(0, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval))) + return 1; + len = recv_peekall(0, hexlen, 4); if (len != 4) return 1; diff --git a/xinetd/git b/xinetd/git index cb1f045..16cb994 100644 --- a/xinetd/git +++ b/xinetd/git @@ -32,7 +32,7 @@ service git { type = UNLISTED - flags = IPv6 + flags = IPv6 KEEPALIVE socket_type = stream protocol = tcp port = 9418 -- 2.11.4.GIT