shm_mq: Third attempt at fixing nowait behavior in shm_mq_receive.
authorRobert Haas
Tue, 3 Nov 2015 14:12:52 +0000 (09:12 -0500)
committerRobert Haas
Tue, 3 Nov 2015 14:20:34 +0000 (09:20 -0500)
commit038aa89af53ee6ee26dfc9e73704d4e94701588f
tree8264c189857c01453bc9c01c9f29cca8127874f4
parent11e7f9d52e2108f340213e51a8114a832b0ccc52
shm_mq: Third attempt at fixing nowait behavior in shm_mq_receive.

Commit a1480ec1d3bacb9acb08ec09f22bc25bc033115b purported to fix the
problems with commit b2ccb5f4e6c81305386edb34daf7d1d1e1ee112a, but it
didn't completely fix them.  The problem is that the checks were
performed in the wrong order, leading to a race condition.  If the
sender attached, sent a message, and detached after the receiver
called shm_mq_get_sender and before the receiver called
shm_mq_counterparty_gone, we'd incorrectly return SHM_MQ_DETACHED
before all messages were read.  Repair by reversing the order of
operations, and add a long comment explaining why this new logic is
(hopefully) correct.
src/backend/storage/ipc/shm_mq.c