From c808648c3ca82b4d2773cf3e1afbf26c94690134 Mon Sep 17 00:00:00 2001
From: Jelte Fennema <jelte.fennema@microsoft.com>
Date: Fri, 1 Oct 2021 08:59:17 +0200
Subject: [PATCH] Consider ETIMEDOUT a connection failure when TCP_USER_TIMEOUT
 is defined

When the TCP_USER_TIMEOUT socket option is defined on a connection and
the timeout is reached, it will cause a read to return ETIMEDOUT. After
that the socket will be closed by the kernel. This considers ETIMEDOUT
an unrecoverable connection failure when TCP_USER_TIMEOUT is defined.

It specifically does not do make this change when TCP_USER_TIMEOUT is
not defined. This is to reduce the chance of introducing issues and also
so that win32_port.h does not have to be changed in an ABI incompatible
way.
---
 src/include/port.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/include/port.h b/src/include/port.h
index 82f63de325..778da3558f 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -111,6 +111,18 @@ extern void pgfnames_cleanup(char **filenames);
  * are actually reporting errors typically single out EPIPE and ECONNRESET,
  * while allowing the network failures to be reported generically.
  */
+#ifdef TCP_USER_TIMEOUT
+#define ALL_CONNECTION_FAILURE_ERRNOS \
+	EPIPE: \
+	case ECONNRESET: \
+	case ECONNABORTED: \
+	case EHOSTDOWN: \
+	case EHOSTUNREACH: \
+	case ENETDOWN: \
+	case ENETRESET: \
+	case ENETUNREACH: \
+	case ETIMEDOUT
+#else
 #define ALL_CONNECTION_FAILURE_ERRNOS \
 	EPIPE: \
 	case ECONNRESET: \
@@ -120,6 +132,7 @@ extern void pgfnames_cleanup(char **filenames);
 	case ENETDOWN: \
 	case ENETRESET: \
 	case ENETUNREACH
+#endif
 
 /* Portable locale initialization (in exec.c) */
 extern void set_pglocale_pgservice(const char *argv0, const char *app);
-- 
2.17.1

