Skip to content

Commit 4adc803

Browse files
committed
fix: Ensure all requests calls have a timeout
1 parent 69c7e5a commit 4adc803

10 files changed

Lines changed: 18 additions & 13 deletions

File tree

.github/workflows/make_release.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def make_release(version, commit_hash, release_notes=""):
2929
"prerelease": Version(version).is_prerelease,
3030
},
3131
headers=headers,
32+
timeout=30,
3233
)
3334
r.raise_for_status()
3435
release_data = r.json()
@@ -41,6 +42,7 @@ def make_release(version, commit_hash, release_notes=""):
4142
"draft": False,
4243
},
4344
headers=headers,
45+
timeout=30,
4446
)
4547
r.raise_for_status()
4648
release_data = r.json()

src/DIRAC/Core/Security/IAMService.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _getIamPagedResources(self, url):
6565
totalResults = 1000 # total number of users
6666
itemsPerPage = 10
6767
while startIndex <= totalResults:
68-
resp = requests.get(url, headers=headers, params={"startIndex": startIndex})
68+
resp = requests.get(url, headers=headers, params={"startIndex": startIndex}, timeout=30)
6969
resp.raise_for_status()
7070
data = resp.json()
7171
# These 2 should never change while looping

src/DIRAC/Core/Security/VOMSService.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ def getUsers(self):
8080
cert=getProxyLocation(),
8181
verify=getCAsLocation(),
8282
params={"startIndex": str(startIndex), "pageSize": "100"},
83+
timeout=30,
8384
)
84-
except requests.ConnectionError as exc:
85+
except (requests.ConnectionError,requests.Timeout) as exc:
8586
error = f"{url}:{repr(exc)}"
8687
urlDone = True
8788
continue

src/DIRAC/DataManagementSystem/Client/FTS3Job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_scitag(vo: str, activity: Optional[str] = None) -> int:
6969
@cached(_scitag_json_cache, lock=_scitag_json_lock)
7070
def get_remote_json():
7171
gLogger.verbose("Fetching https://scitags.org/api.json from the network")
72-
response = requests.get("https://scitags.org/api.json")
72+
response = requests.get("https://scitags.org/api.json", timeout=30)
7373
response.raise_for_status()
7474
return response.json()
7575

src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def export_updateSoftware(self, version):
354354
)
355355
self.log.info("Downloading DIRACOS2 installer from", installer_url)
356356
with tempfile.NamedTemporaryFile(suffix=".sh", mode="wb") as installer:
357-
with requests.get(installer_url, stream=True) as r:
357+
with requests.get(installer_url, timeout=30, stream=True) as r:
358358
if not r.ok:
359359
return S_ERROR(f"Failed to download {installer_url}")
360360
for chunk in r.iter_content(chunk_size=1024**2):

src/DIRAC/ResourceStatusSystem/PolicySystem/Actions/SlackAction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ def sendSlackMessage(self, message):
115115
"""
116116

117117
payload = {"text": message}
118-
response = requests.post(self.url, data=json.dumps(payload), headers={"Content-Type": "application/json"})
118+
response = requests.post(self.url, data=json.dumps(payload), headers={"Content-Type": "application/json"}, timeout=30)
119119
response.raise_for_status()
120120
return S_OK()

src/DIRAC/Resources/IdProvider/OAuth2IdProvider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ def submitDeviceCodeAuthorizationFlow(self, group=None):
577577
self.get_metadata("device_authorization_endpoint"),
578578
data=dict(client_id=self.client_id, scope=list_to_scope(scope_to_list(self.scope) + groupScopes)),
579579
verify=self.verify,
580+
timeout=30,
580581
)
581582
r.raise_for_status()
582583
deviceResponse = r.json()
@@ -616,6 +617,7 @@ def waitFinalStatusOfDeviceCodeAuthorizationFlow(self, deviceCode, interval=5, t
616617
self.get_metadata("token_endpoint"),
617618
data=dict(client_id=self.client_id, grant_type=DEVICE_CODE_GRANT_TYPE, device_code=deviceCode),
618619
verify=self.verify,
620+
timeout=30,
619621
)
620622
token = r.json()
621623
if not token:

src/DIRAC/Resources/Storage/S3Storage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _getKeyFromURL(self, url):
187187
# failed[key] = res['Message']
188188
# continue
189189
# presignedURL = res['Value']
190-
# response = requests.get(presignedURL)
190+
# response = requests.get(presignedURL, timeout=30)
191191
# if response.status_code == 200:
192192
# successful[key] = True
193193
# elif response.status_code == 404: # not found
@@ -268,7 +268,7 @@ def _presigned_exists(self, urls):
268268
# and perform it with requests
269269
for url, presignedURL in presignedURLs.items():
270270
try:
271-
response = requests.get(presignedURL)
271+
response = requests.get(presignedURL, timeout=30)
272272
if response.status_code == 200:
273273
successful[url] = True
274274
elif response.status_code == 404: # not found
@@ -373,7 +373,7 @@ def _presigned_getFile(self, urls, localPath=False):
373373

374374
# Stream download to save memory
375375
# https://requests.readthedocs.io/en/latest/user/advanced/#body-content-workflow
376-
with requests.get(presignedURL, stream=True) as r:
376+
with requests.get(presignedURL, timeout=30, stream=True) as r:
377377
r.raise_for_status()
378378
with open(dest_file, "wb") as f:
379379
for chunk in r.iter_content():
@@ -489,7 +489,7 @@ def _presigned_putFile(self, urls, sourceSize=0):
489489
with open(src_file, "rb") as src_fd:
490490
# files = {'file': (dest_key, src_fd)}
491491
files = {"file": src_fd}
492-
response = requests.post(presignedURL, data=presignedFields, files=files)
492+
response = requests.post(presignedURL, data=presignedFields, files=files, timeout=30)
493493

494494
if not response.ok:
495495
raise Exception(response.reason)
@@ -567,7 +567,7 @@ def _presigned_getFileMetadata(self, urls):
567567

568568
for url, presignedURL in presignedURLs.items():
569569
try:
570-
response = requests.head(presignedURL)
570+
response = requests.head(presignedURL, timeout=30)
571571
if not response.ok:
572572
raise Exception(response.reason)
573573

@@ -652,7 +652,7 @@ def _presigned_removeFile(self, urls):
652652

653653
for url, presignedURL in presignedURLs.items():
654654
try:
655-
response = requests.delete(presignedURL)
655+
response = requests.delete(presignedURL, timeout=30)
656656
if not response.ok:
657657
raise Exception(response.reason)
658658

src/DIRAC/WorkloadManagementSystem/Agent/PilotSyncAgent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def execute(self):
109109
self.log.info("Attempting to upload", f"to {server}")
110110
if server.startswith("https://"):
111111
for tf in allFiles:
112-
res = requests.put(server, data=tf, verify=self.casLocation, cert=self.certAndKeyLocation)
112+
res = requests.put(server, data=tf, verify=self.casLocation, cert=self.certAndKeyLocation, timeout=30)
113113
if res.status_code not in (200, 202):
114114
self.log.error("Could not upload", f"to {server}: status {res.status_code}")
115115
else: # Assumes this is a DIRAC SE

src/DIRAC/WorkloadManagementSystem/Service/SandboxStoreHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _sendToClient(self, fileID, token, fileHelper=None, raw=False):
374374
if filePath.startswith("/S3"):
375375
with TheImpersonator(credDict, source="SandboxStore") as client:
376376
res = client.jobs.get_sandbox_file(pfn=filePath)
377-
r = requests.get(res.url)
377+
r = requests.get(res.url, timeout=30)
378378
r.raise_for_status()
379379
sbData = r.content
380380
if fileHelper:

0 commit comments

Comments
 (0)