From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Andres Freund <andres(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers(at)postgresql(dot)org, Daniel Farina <daniel(at)heroku(dot)com> |
Subject: | Re: Detecting libpq connections improperly shared via fork() |
Date: | 2012-10-09 18:58:26 |
Message-ID: | 20121009185826.GA12481@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Oct 04, 2012 at 12:14:02AM +0200, Andres Freund wrote:
> On Thursday, October 04, 2012 12:08:18 AM Daniel Farina wrote:
> > It would be fantastic for libpq to somehow monitor use of a connection
> > from multiple PIDs that share a parent and deliver an error indicating
> > what is wrong. Unfortunately detecting that would require either a
> > file or some kind of shared memory map, AFAIK, and I don't know how
> > keen anyone is on accepting that patch. So, may I ask: how keen is
> > anyone on accepting such a patch, and under what conditions of
> > mechanism?
> Hm. An easier version of this could just be storing the pid of the process
> that did the PQconnectdb* in the PGconn struct. You can then check that
> PGconn->pid == getpid() at relatively few places and error out on a mismatch.
> That should be doable with only minor overhead.
On system's that support it, pthread_atfork() might help. Though being
like a signal handler you don't have access to the PGconn structure, so
you can't flag anything easily. Maybe just to cache getpid()?
In any case, adding a check to PQexec and friends would probably be
sufficient, since that's what every program is going to start with.
Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
-- Arthur Schopenhauer
From | Date | Subject | |
---|---|---|---|
Next Message | John R Pierce | 2012-10-09 19:00:18 | Re: pgxs problem... |
Previous Message | Heikki Linnakangas | 2012-10-09 17:01:56 | Re: Switching timeline over streaming replication |