@@ -548,6 +548,9 @@ receive_array(SHMRequest request, Size item_size, Size *count)
548548 * We switch to TopMemoryContext, so that recv_mqh is allocated there
549549 * and is guaranteed to survive until before_shmem_exit callbacks are
550550 * 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().
551554 */
552555 oldctx = MemoryContextSwitchTo (TopMemoryContext );
553556 recv_mqh = shm_mq_attach (recv_mq , NULL , NULL );
@@ -566,10 +569,8 @@ receive_array(SHMRequest request, Size item_size, Size *count)
566569 {
567570 res = shm_mq_receive (recv_mqh , & len , & data , false);
568571 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+
573574 memcpy (count , data , sizeof (* count ));
574575
575576 result = palloc (item_size * (* count ));
@@ -579,10 +580,8 @@ receive_array(SHMRequest request, Size item_size, Size *count)
579580 {
580581 res = shm_mq_receive (recv_mqh , & len , & data , false);
581582 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+
586585 memcpy (ptr , data , item_size );
587586 ptr += item_size ;
588587 }
@@ -591,7 +590,6 @@ receive_array(SHMRequest request, Size item_size, Size *count)
591590
592591 /* We still have to detach and release lock during normal operation. */
593592 shm_mq_detach_compat (recv_mqh , recv_mq );
594-
595593 LockRelease (& queueTag , ExclusiveLock , false);
596594
597595 return result ;
0 commit comments