Skip to content

Commit

Permalink
[#1744] Added timeouts to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Sep 22, 2023
1 parent 09f11b9 commit 98a6068
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.views.generic import FormView, TemplateView

from django_htmx.http import HttpResponseClientRedirect
from glom import glom
from mail_editor.helpers import find_template
from view_breadcrumbs import BaseBreadcrumbMixin
from zgw_consumers.api_models.constants import RolOmschrijving
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
("nl", _("Dutch")),
]

# Timeouts (connection timeout, read timeout) for requests made with the requests library
REQUESTS_TIMEOUT = (10, 60)

TIME_ZONE = "Europe/Amsterdam" # note: this *may* affect the output of DRF datetimes

Expand Down
5 changes: 4 additions & 1 deletion src/open_inwoner/haalcentraal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def _fetch_brp_data(user_bsn: str, brp_version):
"burgerservicenummer": [user_bsn],
},
request_kwargs=dict(
headers={"Accept": "application/json"}, verify=False
headers={"Accept": "application/json"},
verify=False,
timeout=settings.REQUESTS_TIMEOUT,
),
)
except (RequestException, ClientError) as e:
Expand All @@ -66,6 +68,7 @@ def _fetch_brp_data(user_bsn: str, brp_version):
"fields": "geslachtsaanduiding,naam,geboorte,verblijfplaats"
},
verify=False,
timeout=settings.REQUESTS_TIMEOUT,
),
)
except (RequestException, ClientError) as e:
Expand Down
20 changes: 17 additions & 3 deletions src/open_inwoner/openzaak/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ def _fetch_single_information_object(
if client is None:
return

request_kwargs = {"timeout": settings.REQUESTS_TIMEOUT}

try:
if url:
response = client.retrieve("enkelvoudiginformatieobject", url=url)
response = client.retrieve(
"enkelvoudiginformatieobject", url=url, request_kwargs=request_kwargs
)
else:
response = client.retrieve("enkelvoudiginformatieobject", uuid=uuid)
response = client.retrieve(
"enkelvoudiginformatieobject", uuid=uuid, request_kwargs=request_kwargs
)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return
Expand Down Expand Up @@ -82,6 +88,8 @@ def download_document(url: str) -> Optional[Response]:
else:
req_args["cert"] = service.client_certificate.public_certificate.path

req_args["timeout"] = settings.REQUESTS_TIMEOUT

try:
res = requests.get(url, **req_args)
res.raise_for_status()
Expand Down Expand Up @@ -118,7 +126,13 @@ def upload_document(
}

try:
response = client.create("enkelvoudiginformatieobject", document_body)
response = client.create(
"enkelvoudiginformatieobject",
document_body,
request_kwargs={
"timeout": settings.REQUESTS_TIMEOUT,
},
)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return
Expand Down

0 comments on commit 98a6068

Please sign in to comment.