Re: Using connection after fork - Mailing list pgsql-general

From Jeff
Subject Re: Using connection after fork
Date
Msg-id 9A359E04-EAD6-11D8-86DE-000393D1F76E@torgo.978.org
Whole thread Raw
In response to Using connection after fork  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: Using connection after fork  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Aug 10, 2004, at 4:41 AM, Peter Eisentraut wrote:

> does the following:  A daemon process opens a database connection,
> forks
> children on request, and those children access the database using that
> inherited connection.  After one request, the child dies.  It seems to
> me

I've been bit by this sort of thing before.  When you fork() the child
inherits all the file descriptors , including the one connected to PG.
But when the child dies  that FD will be closed, thus it will also be
closed in the parent causing "odd behavior".   (At least, that is what
I've seen in my apps)

> that this connection sharing cannot work because the processes would
> get
> mixed up, but the author claims that he has tested this successfully.
> I've
> been trying to figure out the semantics from the libc documentation,
> but I
> can't find a definitive answer.  Does anyone know what will happen in
> this
> situation, and why it actually appears to work?
>

Does it work for sustained periods of time?  Is the parent reconnecting
to PG after each child dies?  It *shouldn't* work.


--
Jeff Trout <jeff@jefftrout.com>
http://www.jefftrout.com/
http://www.stuarthamm.net/


pgsql-general by date:

Previous
From: Raphael Bauduin
Date:
Subject: Re: history tables with only one function?
Next
From: Tom Lane
Date:
Subject: Re: Using connection after fork