Re: atexit_callback can be a net negative - Mailing list pgsql-hackers

From Andres Freund
Subject Re: atexit_callback can be a net negative
Date
Msg-id 20140307180647.GA23339@awork2.anarazel.de
Whole thread Raw
In response to Re: atexit_callback can be a net negative  (Peter LaDow <petela@gocougs.wsu.edu>)
List pgsql-hackers
Hi,

On 2014-03-07 09:50:15 -0800, Peter LaDow wrote:
> 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.

I actually didn't see any source code of yours ;), just answered Tom's
question about what to do after exec() failed.

There's several other wierd behaviours if you use exit() instead of
_exit() after a fork, most prominently double flushes leading to
repeated/corrupted output when you have have stream FILEs open in the
parent. This is because the stream will be flushed in both, the parent
(at some later write or exit) and the child (at exit). It's simply
something that won't work well.

> > 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.

The important bit in the sentence you quote is "pg unaware library". My
point is just that there are some special considerations you have to be
aware of. fork() and exec() is a way to escape that environment, and
should be fine.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: What the heck is hobby.2ndquadrant.com?
Next
From: Pavel Stehule
Date:
Subject: proposal (9.5) : psql unicode border line styles