summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-06-27 16:56:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-27 16:56:22 (GMT)
commit0a20325a01d089d8274aa4be05d79e6c157e1319 (patch)
tree6387b48fe601db9936bd788783c2f8e79fd7867f
parent05219a1276341e72d8082d76b7f5ed394b7437a4 (diff)
parenta43b68a196652a0c6b054ee4905ac98d1cdcbbb9 (diff)
downloadgit-0a20325a01d089d8274aa4be05d79e6c157e1319.zip
git-0a20325a01d089d8274aa4be05d79e6c157e1319.tar.gz
git-0a20325a01d089d8274aa4be05d79e6c157e1319.tar.bz2
Merge branch 'ew/daemon-socket-keepalive' into maint
When "git daemon" is run without --[init-]timeout specified, a connection from a client that silently goes offline can hang around for a long time, wasting resources. The socket-level KEEPALIVE has been enabled to allow the OS to notice such failed connections. * ew/daemon-socket-keepalive: daemon: enable SO_KEEPALIVE for all sockets
-rw-r--r--daemon.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/daemon.c b/daemon.c
index 8d45c33..46dddac 100644
--- a/daemon.c
+++ b/daemon.c
@@ -669,6 +669,15 @@ static void hostinfo_clear(struct hostinfo *hi)
strbuf_release(&hi->tcp_port);
}
+static void set_keep_alive(int sockfd)
+{
+ int ka = 1;
+
+ if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0)
+ logerror("unable to set SO_KEEPALIVE on socket: %s",
+ strerror(errno));
+}
+
static int execute(void)
{
char *line = packet_buffer;
@@ -681,6 +690,7 @@ static int execute(void)
if (addr)
loginfo("Connection from %s:%s", addr, port);
+ set_keep_alive(0);
alarm(init_timeout ? init_timeout : timeout);
pktlen = packet_read(0, NULL, NULL, packet_buffer, sizeof(packet_buffer), 0);
alarm(0);
@@ -951,6 +961,8 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
continue;
}
+ set_keep_alive(sockfd);
+
if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
logerror("Could not bind to %s: %s",
ip2str(ai->ai_family, ai->ai_addr, ai->ai_addrlen),
@@ -1010,6 +1022,8 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
return 0;
}
+ set_keep_alive(sockfd);
+
if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
logerror("Could not bind to %s: %s",
ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),