Re: Exporting closePGconn from libpq

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Leon Smith <leon(dot)p(dot)smith(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Exporting closePGconn from libpq
Date: 2011-05-14 15:37:41
Message-ID: 21394.1305387461@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Leon Smith <leon(dot)p(dot)smith(at)gmail(dot)com> writes:
> ... The low-level binding has a couple of options:

> 1. Ignore the issue and allow for the possibility of a segfault if
> the library is used incorrectly, which is not a good situation for
> "safe" languages.

> 2. Create a wrapper that tracks whether or not PQfinish has ever been
> called, so that attempts to use a connection afterwards can be turned
> into native exceptions/other forms of error signaling. This kind of
> solution can introduce their own minor issues.

> 3. Hack libpq to export closePGconn so that libpq can safely signal
> the low-level bindings of the error when a connection is used after it
> is disconnected, reserving PQfinish to run in a GC-triggered
> finalizer. While this is a technically preferable solution, without
> getting the change into upstream sources it is also a deployment
> nightmare.

> Is there any particular reason why closePGconn should not be exported
> from libpq?

Yes: it'd introduce a new externally-visible state that libpq now has to
worry about supporting in all its operations, ie connection closed but
not gone. This state is guaranteed to be poorly tested and hence buggy.

I think you need a wrapper object. Given the context you're describing,
I'd be willing to lay a side bet that you'll end up needing a wrapper
anyway, even if it seems like you could avoid it right now. Language
embeddings of libpq tend to accrete features...

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Leon Smith 2011-05-14 15:59:12 Re: Exporting closePGconn from libpq
Previous Message Leon Smith 2011-05-14 15:23:13 Exporting closePGconn from libpq