Commit 846f8c94 authored by Robert Haas's avatar Robert Haas

Fix attach-related race condition in shm_mq_send_bytes.

Spotted by Antonin Houska.
parent 4eda0a64
......@@ -777,16 +777,12 @@ shm_mq_send_bytes(shm_mq_handle *mqh, Size nbytes, const void *data,
return SHM_MQ_DETACHED;
}
if (available == 0)
if (available == 0 && !mqh->mqh_counterparty_attached)
{
shm_mq_result res;
/*
* The queue is full, so if the receiver isn't yet known to be
* attached, we must wait for that to happen.
*/
if (!mqh->mqh_counterparty_attached)
{
if (nowait)
{
if (shm_mq_get_receiver(mq) == NULL)
......@@ -803,7 +799,15 @@ shm_mq_send_bytes(shm_mq_handle *mqh, Size nbytes, const void *data,
return SHM_MQ_DETACHED;
}
mqh->mqh_counterparty_attached = true;
/*
* The receiver may have read some data after attaching, so we
* must not wait without rechecking the queue state.
*/
}
else if (available == 0)
{
shm_mq_result res;
/* Let the receiver know that we need them to read some data. */
res = shm_mq_notify_receiver(mq);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment