2020import stat
2121import struct
2222import sys
23- import time
2423import typing
2524import urllib .parse
2625import warnings
@@ -55,7 +54,6 @@ def parse(cls, sslmode):
5554 'ssl' ,
5655 'sslmode' ,
5756 'direct_tls' ,
58- 'connect_timeout' ,
5957 'server_settings' ,
6058 'target_session_attrs' ,
6159 ])
@@ -262,7 +260,7 @@ def _dot_postgresql_path(filename) -> typing.Optional[pathlib.Path]:
262260
263261def _parse_connect_dsn_and_args (* , dsn , host , port , user ,
264262 password , passfile , database , ssl ,
265- direct_tls , connect_timeout , server_settings ,
263+ direct_tls , server_settings ,
266264 target_session_attrs ):
267265 # `auth_hosts` is the version of host information for the purposes
268266 # of reading the pgpass file.
@@ -655,14 +653,14 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
655653 params = _ConnectionParameters (
656654 user = user , password = password , database = database , ssl = ssl ,
657655 sslmode = sslmode , direct_tls = direct_tls ,
658- connect_timeout = connect_timeout , server_settings = server_settings ,
656+ server_settings = server_settings ,
659657 target_session_attrs = target_session_attrs )
660658
661659 return addrs , params
662660
663661
664662def _parse_connect_arguments (* , dsn , host , port , user , password , passfile ,
665- database , timeout , command_timeout ,
663+ database , command_timeout ,
666664 statement_cache_size ,
667665 max_cached_statement_lifetime ,
668666 max_cacheable_statement_size ,
@@ -695,7 +693,7 @@ def _parse_connect_arguments(*, dsn, host, port, user, password, passfile,
695693 dsn = dsn , host = host , port = port , user = user ,
696694 password = password , passfile = passfile , ssl = ssl ,
697695 direct_tls = direct_tls , database = database ,
698- connect_timeout = timeout , server_settings = server_settings ,
696+ server_settings = server_settings ,
699697 target_session_attrs = target_session_attrs )
700698
701699 config = _ClientConfiguration (
@@ -799,17 +797,13 @@ async def _connect_addr(
799797 * ,
800798 addr ,
801799 loop ,
802- timeout ,
803800 params ,
804801 config ,
805802 connection_class ,
806803 record_class
807804):
808805 assert loop is not None
809806
810- if timeout <= 0 :
811- raise asyncio .TimeoutError
812-
813807 params_input = params
814808 if callable (params .password ):
815809 password = params .password ()
@@ -827,21 +821,16 @@ async def _connect_addr(
827821 params_retry = params ._replace (ssl = None )
828822 else :
829823 # skip retry if we don't have to
830- return await __connect_addr (params , timeout , False , * args )
824+ return await __connect_addr (params , False , * args )
831825
832826 # first attempt
833- before = time .monotonic ()
834827 try :
835- return await __connect_addr (params , timeout , True , * args )
828+ return await __connect_addr (params , True , * args )
836829 except _RetryConnectSignal :
837830 pass
838831
839832 # second attempt
840- timeout -= time .monotonic () - before
841- if timeout <= 0 :
842- raise asyncio .TimeoutError
843- else :
844- return await __connect_addr (params_retry , timeout , False , * args )
833+ return await __connect_addr (params_retry , False , * args )
845834
846835
847836class _RetryConnectSignal (Exception ):
@@ -850,7 +839,6 @@ class _RetryConnectSignal(Exception):
850839
851840async def __connect_addr (
852841 params ,
853- timeout ,
854842 retry ,
855843 addr ,
856844 loop ,
@@ -882,15 +870,10 @@ async def __connect_addr(
882870 else :
883871 connector = loop .create_connection (proto_factory , * addr )
884872
885- connector = asyncio .ensure_future (connector )
886- before = time .monotonic ()
887- tr , pr = await compat .wait_for (connector , timeout = timeout )
888- timeout -= time .monotonic () - before
873+ tr , pr = await connector
889874
890875 try :
891- if timeout <= 0 :
892- raise asyncio .TimeoutError
893- await compat .wait_for (connected , timeout = timeout )
876+ await connected
894877 except (
895878 exceptions .InvalidAuthorizationSpecificationError ,
896879 exceptions .ConnectionDoesNotExistError , # seen on Windows
@@ -993,23 +976,21 @@ async def _can_use_connection(connection, attr: SessionAttribute):
993976 return await can_use (connection )
994977
995978
996- async def _connect (* , loop , timeout , connection_class , record_class , ** kwargs ):
979+ async def _connect (* , loop , connection_class , record_class , ** kwargs ):
997980 if loop is None :
998981 loop = asyncio .get_event_loop ()
999982
1000- addrs , params , config = _parse_connect_arguments (timeout = timeout , ** kwargs )
983+ addrs , params , config = _parse_connect_arguments (** kwargs )
1001984 target_attr = params .target_session_attrs
1002985
1003986 candidates = []
1004987 chosen_connection = None
1005988 last_error = None
1006989 for addr in addrs :
1007- before = time .monotonic ()
1008990 try :
1009991 conn = await _connect_addr (
1010992 addr = addr ,
1011993 loop = loop ,
1012- timeout = timeout ,
1013994 params = params ,
1014995 config = config ,
1015996 connection_class = connection_class ,
@@ -1019,10 +1000,8 @@ async def _connect(*, loop, timeout, connection_class, record_class, **kwargs):
10191000 if await _can_use_connection (conn , target_attr ):
10201001 chosen_connection = conn
10211002 break
1022- except ( OSError , asyncio . TimeoutError , ConnectionError ) as ex :
1003+ except OSError as ex :
10231004 last_error = ex
1024- finally :
1025- timeout -= time .monotonic () - before
10261005 else :
10271006 if target_attr == SessionAttribute .prefer_standby and candidates :
10281007 chosen_connection = random .choice (candidates )
0 commit comments