On Fri, Mar 7, 2014 at 2:40 PM, Robert Haas <robertmh...@gmail.com> wrote:
>> The big picture here is that in the scenario being debated in the other
>> thread, exit() in a child process forked from a backend will execute that
>> backend's on_detach actions *even if the code had done on_exit_reset after
>> the fork*.
>
> Hmm.  So the problematic sequence of events is where a postmaster
> child forks, and then exits without exec-ing, perhaps because e.g.
> exec fails?

I've attempted a fix for this case.  The attached patch makes
test_shm_mq fork() a child process that calls on_exit_reset() and then
exits.  Without the fix I just pushed, this causes the tests to fail;
with this fix, this does not cause the tests to fail.

I'm not entirely sure that this is exactly right, but I think it's an
improvement.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git a/contrib/test_shm_mq/test.c b/contrib/test_shm_mq/test.c
index 59f18ec..f6b9dd4 100644
--- a/contrib/test_shm_mq/test.c
+++ b/contrib/test_shm_mq/test.c
@@ -13,8 +13,11 @@
 
 #include "postgres.h"
 
+#include <unistd.h>
+
 #include "fmgr.h"
 #include "miscadmin.h"
+#include "storage/ipc.h"
 
 #include "test_shm_mq.h"
 
@@ -72,6 +75,15 @@ test_shm_mq(PG_FUNCTION_ARGS)
 	/* Set up dynamic shared memory segment and background workers. */
 	test_shm_mq_setup(queue_size, nworkers, &seg, &outqh, &inqh);
 
+	/* Try forking a child that immediately exits. */
+	if (fork() == 0)
+	{
+		elog(LOG, "child is PID %d", getpid());
+		on_exit_reset();
+		exit(0);
+	}
+	elog(LOG, "parent is PID %d", getpid());
+
 	/* Send the initial message. */
 	res = shm_mq_send(outqh, message_size, message_contents, false);
 	if (res != SHM_MQ_SUCCESS)
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to