1
1
import threading
2
2
from getpass import getpass
3
- from typing import BinaryIO , Optional , Union
3
+ from typing import TYPE_CHECKING , BinaryIO , Optional , Union
4
4
5
5
from dvc_objects .fs .base import AnyFSPath , FileSystem
6
6
from dvc_objects .fs .callbacks import DEFAULT_CALLBACK , Callback
7
7
from dvc_objects .fs .errors import ConfigError
8
8
from funcy import cached_property , memoize , wrap_with
9
9
10
+ if TYPE_CHECKING :
11
+ from ssl import SSLContext
12
+
10
13
11
14
@wrap_with (threading .Lock ())
12
15
@memoize
13
16
def ask_password (host , user ):
14
17
return getpass (f"Enter a password for host '{ host } ' user '{ user } ':\n " )
15
18
16
19
17
- def make_context (ssl_verify ):
20
+ def make_context (
21
+ ssl_verify : Union [bool , str , None ]
22
+ ) -> Union ["SSLContext" , bool , None ]:
18
23
if isinstance (ssl_verify , bool ) or ssl_verify is None :
19
24
return ssl_verify
20
25
@@ -40,7 +45,6 @@ class HTTPFileSystem(FileSystem):
40
45
41
46
def _prepare_credentials (self , ** config ):
42
47
import aiohttp
43
- from fsspec .asyn import fsspec_loop
44
48
45
49
credentials = {}
46
50
client_kwargs = credentials .setdefault ("client_kwargs" , {})
@@ -74,27 +78,12 @@ def _prepare_credentials(self, **config):
74
78
f"Auth method { auth_method !r} is not supported."
75
79
)
76
80
77
- # Force cleanup of closed SSL transports.
78
- # https://github.com/iterative/dvc/issues/7414
79
- connector_kwargs = {"enable_cleanup_closed" : True }
80
-
81
81
if "ssl_verify" in config :
82
- connector_kwargs .update (ssl = make_context (config ["ssl_verify" ]))
83
-
84
- with fsspec_loop ():
85
- client_kwargs ["connector" ] = aiohttp .TCPConnector (
86
- ** connector_kwargs
87
- )
88
- # The connector should not be owned by aiohttp.ClientSession since
89
- # it is closed by fsspec (HTTPFileSystem.close_session)
90
- client_kwargs ["connector_owner" ] = False
91
-
92
- client_kwargs ["connect_timeout" ] = config .get (
93
- "connect_timeout" , self .REQUEST_TIMEOUT
94
- )
95
- client_kwargs ["read_timeout" ] = config .get (
96
- "read_timeout" , self .REQUEST_TIMEOUT
97
- )
82
+ client_kwargs ["ssl_verify" ] = config ["ssl_verify" ]
83
+
84
+ for timeout in ("connect_timeout" , "read_timeout" ):
85
+ if timeout in config :
86
+ client_kwargs [timeout ] = config .get (timeout )
98
87
99
88
# Allow reading proxy configurations from the environment.
100
89
client_kwargs ["trust_env" ] = True
@@ -105,8 +94,6 @@ def _prepare_credentials(self, **config):
105
94
106
95
async def get_client (
107
96
self ,
108
- connect_timeout : Optional [float ],
109
- read_timeout : Optional [float ],
110
97
** kwargs ,
111
98
):
112
99
import aiohttp
@@ -121,16 +108,24 @@ async def get_client(
121
108
exceptions = {aiohttp .ClientError },
122
109
)
123
110
124
- # The default timeout for the aiohttp is 300 seconds
125
- # which is too low for DVC's interactions (especially
126
- # on the read) when dealing with large data blobs. We
127
- # unlimit the total time to read, and only limit the
128
- # time that is spent when connecting to the remote server.
111
+ # The default total timeout for an aiohttp request is 300 seconds
112
+ # which is too low for DVC's interactions when dealing with large
113
+ # data blobs. We remove the total timeout, and only limit the time
114
+ # that is spent when connecting to the remote server and waiting
115
+ # for new data portions.
116
+ connect_timeout = kwargs .get ("connect_timeout" , self .REQUEST_TIMEOUT )
129
117
kwargs ["timeout" ] = aiohttp .ClientTimeout (
130
118
total = None ,
131
119
connect = connect_timeout ,
132
120
sock_connect = connect_timeout ,
133
- sock_read = read_timeout ,
121
+ sock_read = kwargs .get ("read_timeout" , self .REQUEST_TIMEOUT ),
122
+ )
123
+
124
+ kwargs ["connector" ] = aiohttp .TCPConnector (
125
+ # Force cleanup of closed SSL transports.
126
+ # See https://github.com/iterative/dvc/issues/7414
127
+ enable_cleanup_closed = True ,
128
+ ssl = make_context (kwargs .get ("ssl_verify" )),
134
129
)
135
130
136
131
return ReadOnlyRetryClient (** kwargs )
0 commit comments