Skip to content

Commit b484ddf

Browse files
committed
Treat ETIMEDOUT as indicating a non-recoverable connection failure.
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
1 parent d03bca4 commit b484ddf

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/backend/port/win32/socket.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ int pgwin32_noblock = 0;
4747
*
4848
* Note: where there is a direct correspondence between a WSAxxx error code
4949
* and a Berkeley error symbol, this mapping is actually a no-op, because
50-
* in win32.h we redefine the network-related Berkeley error symbols to have
51-
* the values of their WSAxxx counterparts. The point of the switch is
50+
* in win32_port.h we redefine the network-related Berkeley error symbols to
51+
* have the values of their WSAxxx counterparts. The point of the switch is
5252
* mostly to translate near-miss error codes into something that's sensible
5353
* in the Berkeley universe.
5454
*/
@@ -141,10 +141,15 @@ TranslateSocketError(void)
141141
case WSAEDISCON:
142142
errno = ENOTCONN;
143143
break;
144+
case WSAETIMEDOUT:
145+
errno = ETIMEDOUT;
146+
break;
144147
default:
145148
ereport(NOTICE,
146-
(errmsg_internal("unrecognized win32 socket error code: %d", WSAGetLastError())));
149+
(errmsg_internal("unrecognized win32 socket error code: %d",
150+
WSAGetLastError())));
147151
errno = EINVAL;
152+
break;
148153
}
149154
}
150155

src/include/port.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ extern void pgfnames_cleanup(char **filenames);
119119
case EHOSTUNREACH: \
120120
case ENETDOWN: \
121121
case ENETRESET: \
122-
case ENETUNREACH
122+
case ENETUNREACH: \
123+
case ETIMEDOUT
123124

124125
/* Portable locale initialization (in exec.c) */
125126
extern void set_pglocale_pgservice(const char *argv0, const char *app);

src/include/port/win32_port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ extern int _pgstat64(const char *name, struct stat *buf);
381381
#define ENETUNREACH WSAENETUNREACH
382382
#undef ENOTCONN
383383
#define ENOTCONN WSAENOTCONN
384+
#undef ETIMEDOUT
385+
#define ETIMEDOUT WSAETIMEDOUT
384386

385387
/*
386388
* Locale stuff.

src/port/strerror.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,8 @@ get_errno_symbol(int errnum)
250250
#endif
251251
case ESRCH:
252252
return "ESRCH";
253-
#ifdef ETIMEDOUT
254253
case ETIMEDOUT:
255254
return "ETIMEDOUT";
256-
#endif
257255
#ifdef ETXTBSY
258256
case ETXTBSY:
259257
return "ETXTBSY";

0 commit comments

Comments
 (0)