Re: Using connection after fork

From: Jeff <threshar(at)torgo(dot)978(dot)org>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Using connection after fork
Date: 2004-08-10 14:07:23
Message-ID: 9A359E04-EAD6-11D8-86DE-000393D1F76E@torgo.978.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jefftrout(dot)com>
http://www.jefftrout.com/
http://www.stuarthamm.net/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raphael Bauduin 2004-08-10 14:15:50 Re: history tables with only one function?
Previous Message Christoph Haller 2004-08-10 13:44:44 Re: Stored procedures and "pseudo" fields