Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

+5-6
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

-1
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)