Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Treat ETIMEDOUT as indicating a non-recoverable connection failure.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 30 Sep 2021 18:16:08 +0000 (14:16 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 30 Sep 2021 18:16:08 +0000 (14:16 -0400)
Add ETIMEDOUT to ALL_CONNECTION_FAILURE_ERRNOS' list of "errnos that
identify hard failure of a previously-established network connection".
While one could imagine that this is sometimes recoverable, the same
could be said of other entries such as ENETDOWN.

In support of this, handle ETIMEDOUT on par with other socket errors
in relevant infrastructure, such as TranslateSocketError().
(I made a couple of cosmetic adjustments in TranslateSocketError(),
too.)  The code now assumes that ETIMEDOUT is defined everywhere,
which it should be given that POSIX has required it since SUSv2.

Perhaps this should be back-patched, but I'm hesitant to do so given
the lack of previous complaints, and the hazard that there's a small
ABI break on Windows from redefining the symbol.  Even if we decide
to do that, it'd be prudent to let this bake awhile in HEAD first.

Jelte Fennema

Discussion: https://postgr.es/m/AM5PR83MB01782BFF2978505F6D6C559AF7AA9@AM5PR83MB0178.EURPRD83.prod.outlook.com

src/backend/port/win32/socket.c
src/include/port.h
src/include/port/win32_port.h
src/port/strerror.c

index af151e847093c02add27559d04fa135be5765313..70592afe54e37e447d3a54c4b9c56878c8b42fa3 100644 (file)
@@ -47,8 +47,8 @@ int           pgwin32_noblock = 0;
  *
  * Note: where there is a direct correspondence between a WSAxxx error code
  * and a Berkeley error symbol, this mapping is actually a no-op, because
- * in win32.h we redefine the network-related Berkeley error symbols to have
- * the values of their WSAxxx counterparts.  The point of the switch is
+ * in win32_port.h we redefine the network-related Berkeley error symbols to
+ * have the values of their WSAxxx counterparts.  The point of the switch is
  * mostly to translate near-miss error codes into something that's sensible
  * in the Berkeley universe.
  */
@@ -141,10 +141,15 @@ TranslateSocketError(void)
        case WSAEDISCON:
            errno = ENOTCONN;
            break;
+       case WSAETIMEDOUT:
+           errno = ETIMEDOUT;
+           break;
        default:
            ereport(NOTICE,
-                   (errmsg_internal("unrecognized win32 socket error code: %d", WSAGetLastError())));
+                   (errmsg_internal("unrecognized win32 socket error code: %d",
+                                    WSAGetLastError())));
            errno = EINVAL;
+           break;
    }
 }
 
index 82f63de325058761c9d85fafd9569ef1656e8f89..2ff529fa59b687e1e6339c03517d96bdb6ee5e15 100644 (file)
@@ -119,7 +119,8 @@ extern void pgfnames_cleanup(char **filenames);
    case EHOSTUNREACH: \
    case ENETDOWN: \
    case ENETRESET: \
-   case ENETUNREACH
+   case ENETUNREACH: \
+   case ETIMEDOUT
 
 /* Portable locale initialization (in exec.c) */
 extern void set_pglocale_pgservice(const char *argv0, const char *app);
index 05c5a5344206fb2a579b457f8ab796679a2814ac..093a009aee56d9a395d9280dfbac49dc1999ee2c 100644 (file)
@@ -381,6 +381,8 @@ extern int  _pgstat64(const char *name, struct stat *buf);
 #define ENETUNREACH WSAENETUNREACH
 #undef ENOTCONN
 #define ENOTCONN WSAENOTCONN
+#undef ETIMEDOUT
+#define ETIMEDOUT WSAETIMEDOUT
 
 /*
  * Locale stuff.
index c07c983e750246dc2301bc67037c34cde636f6dc..9b98f77b426951e07e30d1f540ebc45d40302cd9 100644 (file)
@@ -250,10 +250,8 @@ get_errno_symbol(int errnum)
 #endif
        case ESRCH:
            return "ESRCH";
-#ifdef ETIMEDOUT
        case ETIMEDOUT:
            return "ETIMEDOUT";
-#endif
 #ifdef ETXTBSY
        case ETXTBSY:
            return "ETXTBSY";