Re: [PATCH] Allow breaking out of hung connection attempts - Mailing list pgsql-hackers

From Ryan Kelly
Subject Re: [PATCH] Allow breaking out of hung connection attempts
Date
Msg-id 20120625120012.GA18559@llserver.lakeliving.com
Whole thread Raw
In response to Re: [PATCH] Allow breaking out of hung connection attempts  (Shigeru HANADA <shigeru.hanada@gmail.com>)
Responses Re: [PATCH] Allow breaking out of hung connection attempts
List pgsql-hackers
Shigeru:

Thank you very much for your review. Comments are inline below, and a
new patch is attached.

On Fri, Jun 22, 2012 at 10:06:53AM +0900, Shigeru HANADA wrote:
> (2012/05/01 0:30), Ryan Kelly wrote:
> >On Mon, Apr 30, 2012 at 09:02:33AM -0400, Alvaro Herrera wrote:
> >>Well, do *you* want it?
> >Of course. That way I can stop patching my psql and go back to using the
> >one that came with my release :)
>
> Here is result of my review of v4 patch.
>
> Submission
> ----------
> - The patch is in context diff format
> - It needs rebase for HEAD, but patch command takes care automatically.
> - Make finishes cleanly, and all regression tests pass
>
> Functionality
> -------------
> After applying this patch, I could cancel connection attempt at
> start-up by pressing Ctrl+C on terminal just after invoking psql
> command with an unused IP address.  Without this patch, such attempt
> ends up with error such as "No route to host" after uninterruptable
> few seconds (maybe the duration until error would depend on
> environment).
>
> Connection attempt by \connect command could be also canceled by
> pressing Ctrl+C on psql prompt.
>
> In addition, I tried setting PGCONNECT_TIMEOUT to 0 (infinite), but
> psql gave up after few seconds, for both start-up and re-connect.
> Is this intentional behavior?
A timeout of 0 (infinite) means to keep trying until we succeed or fail,
not keep trying forever. As you mentioned above, your connection
attempts error out after a few seconds. This is what is happening. In my
environment no such error occurs and as a result psql continues to
attempt to connect for as long as I let it.

> Detail of changes
> -----------------
> Basically this patch consists of three changes:
>
> 1) defer setup of cancel handler until start-up connection has established
> 2) new libpq API PQconnectTimeout which returns connect_timeout
> value of current session
> 3) use asynchronous connection API at \connect psql command, this
> requires API added by 2)
>
> These seem reasonable to achieve canceling connection attempt at
> start-up and \connect, but, as Ryan says, codes added to do_connect
> might need more simplification.
>
> I have some random comments.
>
> - Checking status by calling PQstatus just after
> PQconnectStartParams is necessary.
Yes, I agree.

> - Copying only "select()" part of pqSocketPoll seems not enough,
> should we use poll(2) if it is supported?
I did not think the additional complexity was worth it in this case.
Unless you see some reason to use poll(2) that I do not.

> - Don't we need to clear error message stored in PGconn after
> PQconnectPoll returns OK status, like connectDBComplete?
I do not believe there is a client interface for clearing the error
message. Additionally, the documentation states that PQerrorMessage
"Returns the error message most recently generated by an operation on
the connection." This seems to indicate that the error message should be
cleared as this behavior is part of the contract of PQerrorMessage.

>
> Regards,
> --
> Shigeru HANADA

-Ryan Kelly

Attachment

pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: compiler warnings on mingw
Next
From: "Kevin Grittner"
Date:
Subject: pg_upgrade broken by xlog numbering