8000 shm_mq_sendv: Fix flushing bug when receiver not yet attached. · postgres/postgres@f5bfba5 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5bfba5

Browse files

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

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