summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c2857fb)
raw | patch | inline | side by side (parent: c2857fb)
author | Eric Wong <normalperson@yhbt.net> | |
Tue, 6 Dec 2011 04:39:36 +0000 (04:39 +0000) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 6 Dec 2011 05:06:53 +0000 (21:06 -0800) |
Sockets may never receive notification of some link errors,
causing "git fetch" or similar processes to hang forever.
Enabling keepalive messages allows hung processes to error out
after a few minutes/hours depending on the keepalive settings of
the system.
This is a problem noticed when running non-interactive
cronjobs to mirror repositories using "git fetch".
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
causing "git fetch" or similar processes to hang forever.
Enabling keepalive messages allows hung processes to error out
after a few minutes/hours depending on the keepalive settings of
the system.
This is a problem noticed when running non-interactive
cronjobs to mirror repositories using "git fetch".
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
connect.c | patch | blob | history |
diff --git a/connect.c b/connect.c
index d2ce57f850fa6d0a6de04f6f714dec487ff9f1ed..d725b1794f4a6d272a0cc649f57d99453255f8cc 100644 (file)
--- a/connect.c
+++ b/connect.c
}
}
+static void enable_keepalive(int sockfd)
+{
+ int ka = 1;
+
+ if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, &ka, sizeof(ka)) < 0)
+ fprintf(stderr, "unable to set SO_KEEPALIVE on socket: %s\n",
+ strerror(errno));
+}
+
#ifndef NO_IPV6
static const char *ai_name(const struct addrinfo *ai)
if (sockfd < 0)
die("unable to connect to %s:\n%s", host, error_message.buf);
+ enable_keepalive(sockfd);
+
if (flags & CONNECT_VERBOSE)
fprintf(stderr, "done.\n");
if (sockfd < 0)
die("unable to connect a socket (%s)", strerror(saved_errno));
+ enable_keepalive(sockfd);
+
if (flags & CONNECT_VERBOSE)
fprintf(stderr, "done.\n");