Skip to content

Commit f5bfba5

Browse files
committed
shm_mq_sendv: Fix flushing bug when receiver not yet attached.
With the old logic, when the reciever had not yet attached, we would never call shm_mq_inc_bytes_written(), even if force_flush = true was specified. That could result in a situation where data that the sender believes it has sent is never received. Along the way, remove a useless function prototype for a nonexistent function from shm_mq.h. Commit 4684643 introduced these problems. Pavan Deolasee, with a few changes by me. Discussion: https://postgr.es/m/CABOikdPkwtLLCTnzzmpSMXo3QZa2yXq0J7Q61ssdLFAJYrOVvQ@mail.gmail.com
1 parent 0a050ee commit f5bfba5

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/backend/storage/ipc/shm_mq.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ shm_mq_sendv(shm_mq_handle *mqh, shm_mq_iovec *iov, int iovcnt, bool nowait,
518518

519519
/*
520520
* If the counterparty is known to have attached, we can read mq_receiver
521-
* without acquiring the spinlock and assume it isn't NULL. Otherwise,
522-
* more caution is needed.
521+
* without acquiring the spinlock. Otherwise, more caution is needed.
523522
*/
524523
if (mqh->mqh_counterparty_attached)
525524
receiver = mq->mq_receiver;
@@ -528,9 +527,8 @@ shm_mq_sendv(shm_mq_handle *mqh, shm_mq_iovec *iov, int iovcnt, bool nowait,
528527
SpinLockAcquire(&mq->mq_mutex);
529528
receiver = mq->mq_receiver;
530529
SpinLockRelease(&mq->mq_mutex);
531-
if (receiver == NULL)
532-
return SHM_MQ_SUCCESS;
533-
mqh->mqh_counterparty_attached = true;
530+
if (receiver != NULL)
531+
mqh->mqh_counterparty_attached = true;
534532
}
535533

536534
/*
@@ -541,7 +539,8 @@ shm_mq_sendv(shm_mq_handle *mqh, shm_mq_iovec *iov, int iovcnt, bool nowait,
541539
if (force_flush || mqh->mqh_send_pending > (mq->mq_ring_size >> 2))
542540
{
543541
shm_mq_inc_bytes_written(mq, mqh->mqh_send_pending);
544-
SetLatch(&receiver->procLatch);
542+
if (receiver != NULL)
543+
SetLatch(&receiver->procLatch);
545544
mqh->mqh_send_pending = 0;
546545
}
547546

src/include/storage/shm_mq.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ extern shm_mq_result shm_mq_sendv(shm_mq_handle *mqh, shm_mq_iovec *iov,
7676
int iovcnt, bool nowait, bool force_flush);
7777
extern shm_mq_result shm_mq_receive(shm_mq_handle *mqh,
7878
Size *nbytesp, void **datap, bool nowait);
79-
extern void shm_mq_flush(shm_mq_handle *mqh);
8079

8180
/* Wait for our counterparty to attach to the queue. */
8281
extern shm_mq_result shm_mq_wait_for_attach(shm_mq_handle *mqh);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy