shm_mq: Repair breakage from previous commit.
authorRobert Haas
Fri, 23 Oct 2015 02:01:11 +0000 (22:01 -0400)
committerRobert Haas
Fri, 23 Oct 2015 02:04:05 +0000 (22:04 -0400)
If the counterparty writes some data into the queue and then detaches,
it's wrong to return SHM_MQ_DETACHED right away.  If we do that, we
fail to read whatever was written.

src/backend/storage/ipc/shm_mq.c

index 296f0bda40cabd57c37f3767bb244969d8cb9ded..c386b2207a1191466e28d2aa4ed5517497ca3b37 100644 (file)
@@ -405,10 +405,12 @@ shm_mq_receive(shm_mq_handle *mqh, Size *nbytesp, void **datap, bool nowait)
    {
        if (nowait)
        {
-           if (shm_mq_counterparty_gone(mq, mqh->mqh_handle))
-               return SHM_MQ_DETACHED;
            if (shm_mq_get_sender(mq) == NULL)
+           {
+               if (shm_mq_counterparty_gone(mq, mqh->mqh_handle))
+                   return SHM_MQ_DETACHED;
                return SHM_MQ_WOULD_BLOCK;
+           }
        }
        else if (!shm_mq_wait_internal(mq, &mq->mq_sender, mqh->mqh_handle)
                 && shm_mq_get_sender(mq) == NULL)