• Tom Lane's avatar
    Fix libpq's implementation of per-host connection timeouts. · 1e6e98f7
    Tom Lane authored
    Commit 5f374fe7 attempted to turn the connect_timeout from an overall
    maximum time limit into a per-host limit, but it didn't do a great job of
    that.  The timer would only get restarted if we actually detected timeout
    within connectDBComplete(), not if we changed our attention to a new host
    for some other reason.  In that case the old timeout continued to run,
    possibly causing a premature timeout failure for the new host.
    
    Fix that, and also tweak the logic so that if we do get a timeout,
    we advance to the next available IP address, not to the next host name.
    There doesn't seem to be a good reason to assume that all the IP
    addresses supplied for a given host name will necessarily fail the
    same way as the current one.  Moreover, this conforms better to the
    admittedly-vague documentation statement that the timeout is "per
    connection attempt".  I changed that to "per host name or IP address"
    to be clearer.  (Note that reconnections to the same server, such as for
    switching protocol version or SSL status, don't get their own separate
    timeout; that was true before and remains so.)
    
    Also clarify documentation about the interpretation of connect_timeout
    values less than 2.
    
    This seems like a bug, so back-patch to v10 where this logic came in.
    
    Tom Lane, reviewed by Fabien Coelho
    
    Discussion: https://postgr.es/m/5735.1533828184@sss.pgh.pa.us
    1e6e98f7
fe-connect.c 167 KB