From: | Peter LaDow <petela(at)gocougs(dot)wsu(dot)edu> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: atexit_callback can be a net negative |
Date: | 2014-03-07 17:50:15 |
Message-ID: | CAN8Q1EfmnkzGR42CEisBOMnSn7v0icfsXsxk2ms-7p3amV_mcw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Sorry for the bit of top-posting, but I wanted to make some things
clear. Also, I wasn't subscribed to pgsql-hackers at the time this
thread began, so I apologize for the missing headers that might cause
threading issues.
I'm the submitter of bug #9464. Here's the background on what we are
doing. We are on a limited resource, embedded device. We make use of
the database as an event driven system. In the case of an incoming
event, such as a settings change, we make use of this fork/exec
procedure to spawn an asynchronous process to handle certain events.
Some of these external processes are long running, some need to run
outside the current transaction context, and some we don't care about
the result--we just want it to run.
Also, the on_exit_reset() does clear up the issue, and we have
implemented it as suggested in this thread (calling it immediately
after the fork() in the child). And Andres' keen eye noted we were
calling exit() after an exec() failure, rather than _exit(). Thank
you, Andres, for pointing out this error.
Andres Freund <andres <at> 2ndquadrant.com> writes:
> On 2014-03-07 09:49:05 -0500, Tom Lane wrote:
> > Andres Freund <andres <at> 2ndquadrant.com> writes:
> > > What are you proposing to do in that case? This is only one of the
> > > failure cases of forking carelessly, right?
Just to be clear, we intended to fork careFULLy, not careLESSly.
Hence the reason for the double fork with an eventual exec(). We
intended to be clearly separated from the backend and executing in our
own clean, unrelated context.
> I don't think it's a reasonable pattern run background processes that
> aren't managed by postgres with all shared memory still
> accessible. You'll have to either also detach from shared memory and
In this case we definitely did NOT want to be managed by postgres.
Hence the double fork. The intent was that the first level child
would NOT be managed by postgres, hence the exit().
> related things, or you have to fork() and exec(). At the very least, not
Which is _exactly_ what we were trying to do. The first fork was only
so that we could fork again and spawn a subprocess completely detached
from the postmaster. And also to have something for the postmaster to
reap via waitpid and prevent a zombie from hanging around. The
typical daemon stuff.
> integrating the child with the postmaster's lifetime will prevent
> postgres from restarting because there's still a child attached to the
> shared memory.
Which is _exactly_ what we were NOT trying to do. We did not want to
integrate with postmaster.
> I don't see any way it's be safe for a pg unaware library to start
> forking around and doing similar random things inside normal
> backends.
We aren't exactly "forking around." We were trying to spawn an
asynchronous process without any ties to the postmaster. This was
expected to be well-defined, clean behavior. A fork/exec isn't an
unusual thing to do, and we didn't expect that exiting a child would
invoke behavior that would cause problems.
Thanks,
Pete
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-03-07 17:56:38 | Re: Row-security on updatable s.b. views |
Previous Message | Tom Lane | 2014-03-07 17:46:05 | What the heck is hobby.2ndquadrant.com? |