Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c - Mailing list pgsql-hackers

From Tom Lane
Subject Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c
Date
Msg-id 11258.1034654476@sss.pgh.pa.us
Whole thread Raw
In response to Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: droped out precise time calculations in src/interfaces/libpq/fe-connect.c  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Denis A Ustimenko wrote:
>> Beware of almost 1 second posiible error. For example: connect_timeout == 1,
>> we start at 0.999999 then finish_time == 1. If CPU is quite busy we will
>> do only one iteration. I don't know is it enough to make connection?
>> True timeout in this case == 0.000001

> Good question.  What is going to happen is that select() is going to be
> passed tv_sec = 1, and it is going to sleep for one second.  Now, if
> select is interrupted, another time() call is going to be made.

There is a very simple answer to this, which I think I suggested to Joe
originally, but it's not in the code now: the initial calculation of
finish_time = now() + timeout must add one.  This ensures that any
roundoff error is in the conservative direction of timing out later,
rather than sooner.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: Re: [GENERAL] Postgres-based system to run .org registry?
Next
From: Larry Rosenman
Date:
Subject: PG_DUMP and Adding columns/Types