Re: atexit_callback can be a net negative

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Peter LaDow <petela(at)gocougs(dot)wsu(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: atexit_callback can be a net negative
Date: 2014-03-07 18:06:47
Message-ID: 20140307180647.GA23339@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2014-03-07 18:24:08 proposal (9.5) : psql unicode border line styles
Previous Message Simon Riggs 2014-03-07 18:04:40 Re: What the heck is hobby.2ndquadrant.com?