shm_mq inconsistent behavior of SHM_MQ_DETACHED - Mailing list pgsql-hackers

From Petr Jelinek
Subject shm_mq inconsistent behavior of SHM_MQ_DETACHED
Date
Msg-id 535674B4.2040706@2ndquadrant.com
Whole thread Raw
Responses Re: shm_mq inconsistent behavior of SHM_MQ_DETACHED  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Hi,

I was playing with shm_mq and found a little odd behavior with detaching 
after sending messages.

Following sequence behaves as expected (receiver gets 2 messages):
P1 -> set_sender
P1 -> attach
P2 -> set_receiver
P2 -> attach
P1 -> send
P2 -> receive
P1 -> send
P1 -> detach
P2 -> receive
P2 -> detach

But if I do first receive after detach like in this sequence:
P1 -> set_sender
P1 -> attach
P2 -> set_receiver
P2 -> attach
P1 -> send
P1 -> send
P1 -> detach
P2 -> receive

I get SHM_MQ_DETACHED on the receiver even though there are messages in 
the ring buffer.

The reason for this behavior is that mqh_counterparty_attached is only 
set by shm_mq_receive. This does not seem to be consistent - I would 
either expect to get SHM_MQ_DETACHED always when other party has 
detached or always get all remaining messages that are in queue (and I 
would strongly prefer the latter).

Maybe the shm_mq_get_bytes_written should be used to determine if there 
is something left for us to read in the receiver if we hit the 
!mqh_counterparty_attached code path with detached sender?


--  Petr Jelinek                  http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training &
Services



pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: AXLE Plans for 9.5 and 9.6
Next
From: Tom Lane
Date:
Subject: Re: Store data in pg_toast for custom type fails (bug?)