Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178109778
D62001.1795986816.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D62001.1795986816.diff
View Options
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -35,6 +35,7 @@
#include <sys/uio.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#include <ctype.h>
#include <errno.h>
@@ -60,6 +61,9 @@
/* Maximum length of a line, newline included, for fetch_getln() */
#define FETCH_LINE_MAX 65536
+/* Seconds a connection may stay silent before the first keep-alive probe */
+#define FETCH_KEEPIDLE 60
+
/*** Local data **************************************************************/
/*
@@ -296,6 +300,14 @@
if (flags != -1 && (flags & O_NONBLOCK) == 0)
(void)fcntl(sd, F_SETFL, flags | O_NONBLOCK);
(void)setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt));
+ /*
+ * Notice a peer that has gone away in minutes rather than hours;
+ * how often to probe and how many times is left to
+ * net.inet.tcp.keepintvl and keepcnt.
+ */
+ (void)setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
+ opt = FETCH_KEEPIDLE;
+ (void)setsockopt(sd, IPPROTO_TCP, TCP_KEEPIDLE, &opt, sizeof(opt));
conn->sd = sd;
++conn->ref;
return (conn);
diff --git a/lib/libfetch/fetch.3 b/lib/libfetch/fetch.3
--- a/lib/libfetch/fetch.3
+++ b/lib/libfetch/fetch.3
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 27, 2026
+.Dd November 8, 2026
.Dt FETCH 3
.Os
.Sh NAME
@@ -303,6 +303,24 @@
can safely be set to a relatively low value without fear of
prematurely terminating a long transfer; it will only kick in if the
transfer is stalled.
+.Pp
+TCP keep-alive is enabled on every connection, with the first probe
+sent after a minute of silence, so that when the remote end stops
+responding entirely, because the host has gone away or a NAT or
+firewall in between has dropped the connection's state, the operation
+fails with a timeout even if
+.Va fetchTimeout
+is zero.
+How often probes are sent and how many go unanswered before the
+connection is dropped are set by the
+.Va net.inet.tcp.keepintvl
+and
+.Va net.inet.tcp.keepcnt
+.Xr sysctl 8
+variables; with their defaults this takes about 11 minutes.
+A server which is reachable but sends nothing is not detected this way;
+.Va fetchTimeout
+covers that.
.Sh FILE SCHEME
.Fn fetchXGetFile ,
.Fn fetchGetFile
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 29, 9:13 PM (19 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42062394
Default Alt Text
D62001.1795986816.diff (2 KB)
Attached To
Mode
D62001: libfetch: Enable TCP keep-alive on connections
Attached
Detach File
Event Timeline