commit cc58966ee2133520b224f6be61d87843989cb1d4
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sat Sep 12 11:47:07 2026 +0200

    brlapi: Make connections to localhost timeout after 0.1s
    
    We have seen system configurations where connecting to IPv6 ::1 would just
    hang instead of reporting ECONNREFUSED when brltty is not running, probably
    due to various misconfigured firewalls and whatnot. That is a broken system
    configuration, but better avoid the issue from brlapi by just expecting the
    connection to be fast on localhost.

diff --git a/Programs/brlapi_client.c b/Programs/brlapi_client.c
index 4b8d6187e..91d80e640 100644
--- a/Programs/brlapi_client.c
+++ b/Programs/brlapi_client.c
@@ -929,6 +929,19 @@ static int tryHost(brlapi_handle_t *handle, const char *hostAndPort) {
       }
 #endif /* !__MINGW32__ && !HAVE_POLL */
 
+      const struct in6_addr ip6_localhost = IN6ADDR_LOOPBACK_INIT;
+
+      if ((cur->ai_family == AF_INET
+	    && (ntohl(((struct sockaddr_in *)cur->ai_addr)->sin_addr.s_addr) & IN_CLASSA_NET)
+	      == (INADDR_LOOPBACK & IN_CLASSA_NET))
+	  || (cur->ai_family == AF_INET6
+	    && !memcmp(cur->ai_addr, &ip6_localhost, sizeof(ip6_localhost)))) {
+	/* Local connection, it should be fast, otherwise it means we have a
+	 * firewall blocking us, and then better not wait unnecessarily. */
+	struct timeval tv = { .tv_usec = 100000 };
+	setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+      }
+
       if (connect(sockfd, cur->ai_addr, cur->ai_addrlen)<0) {
         closeSocketDescriptor(sockfd);
         continue;
