@@ -548,6 +548,9 @@ receive_array(SHMRequest request, Size item_size, Size *count)
548
548
* We switch to TopMemoryContext, so that recv_mqh is allocated there
549
549
* and is guaranteed to survive until before_shmem_exit callbacks are
550
550
* fired. Anyway, shm_mq_detach() will free handler on its own.
551
+ *
552
+ * NB: we do not pass `seg` to shm_mq_attach(), so it won't set its own
553
+ * callback, i.e. we do not interfere here with shm_mq_detach_callback().
551
554
*/
552
555
oldctx = MemoryContextSwitchTo (TopMemoryContext );
553
556
recv_mqh = shm_mq_attach (recv_mq , NULL , NULL );
@@ -566,10 +569,8 @@ receive_array(SHMRequest request, Size item_size, Size *count)
566
569
{
567
570
res = shm_mq_receive (recv_mqh , & len , & data , false);
568
571
if (res != SHM_MQ_SUCCESS || len != sizeof (* count ))
569
- {
570
- shm_mq_detach_compat (recv_mqh , recv_mq );
571
- elog (ERROR , "Error reading mq." );
572
- }
572
+ elog (ERROR , "error reading mq" );
573
+
573
574
memcpy (count , data , sizeof (* count ));
574
575
575
576
result = palloc (item_size * (* count ));
@@ -579,10 +580,8 @@ receive_array(SHMRequest request, Size item_size, Size *count)
579
580
{
580
581
res = shm_mq_receive (recv_mqh , & len , & data , false);
581
582
if (res != SHM_MQ_SUCCESS || len != item_size )
582
- {
583
- shm_mq_detach_compat (recv_mqh , recv_mq );
584
- elog (ERROR , "Error reading mq." );
585
- }
583
+ elog (ERROR , "error reading mq" );
584
+
586
585
memcpy (ptr , data , item_size );
587
586
ptr += item_size ;
588
587
}
@@ -591,7 +590,6 @@ receive_array(SHMRequest request, Size item_size, Size *count)
591
590
592
591
/* We still have to detach and release lock during normal operation. */
593
592
shm_mq_detach_compat (recv_mqh , recv_mq );
594
-
595
593
LockRelease (& queueTag , ExclusiveLock , false);
596
594
597
595
return result ;
0 commit comments