Error out if waiting on socket readiness without a specified socket.
authorAndres Freund
Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)
committerAndres Freund
Fri, 18 Mar 2016 18:46:45 +0000 (11:46 -0700)
Previously we just ignored such an attempt, but that seems to serve no
purpose but making things harder to debug.

Discussion: 20160114143931[email protected]
    20151230173734[email protected]
Reviewed-By: Robert Haas
src/backend/port/unix_latch.c
src/backend/port/win32_latch.c

index 2ad609c436ea04b312051c97e1389b0ba07457a5..9f8b8d54f079ae6abbcb70d0dafce82f997748fc 100644 (file)
@@ -226,12 +226,13 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
    int         hifd;
 #endif
 
-   /* Ignore WL_SOCKET_* events if no valid socket is given */
-   if (sock == PGINVALID_SOCKET)
-       wakeEvents &= ~(WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE);
-
    Assert(wakeEvents != 0);    /* must have at least one wake event */
 
+   /* waiting for socket readiness without a socket indicates a bug */
+   if (sock == PGINVALID_SOCKET &&
+       (wakeEvents & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)) != 0)
+       elog(ERROR, "cannot wait on socket event without a socket");
+
    if ((wakeEvents & WL_LATCH_SET) && latch->owner_pid != MyProcPid)
        elog(ERROR, "cannot wait on a latch owned by another process");
 
index 80adc13e68ab6e483fad79d61b361ace8d329c57..b1b071339ee3740651fe5aa5603102510dc055d8 100644 (file)
@@ -113,12 +113,13 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
    int         result = 0;
    int         pmdeath_eventno = 0;
 
-   /* Ignore WL_SOCKET_* events if no valid socket is given */
-   if (sock == PGINVALID_SOCKET)
-       wakeEvents &= ~(WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE);
-
    Assert(wakeEvents != 0);    /* must have at least one wake event */
 
+   /* waiting for socket readiness without a socket indicates a bug */
+   if (sock == PGINVALID_SOCKET &&
+       (wakeEvents & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)) != 0)
+       elog(ERROR, "cannot wait on socket event without a socket");
+
    if ((wakeEvents & WL_LATCH_SET) && latch->owner_pid != MyProcPid)
        elog(ERROR, "cannot wait on a latch owned by another process");