Skip to content

Commit

Permalink
fix(xmlupload): make sure resources aren't created multiple times aft…
Browse files Browse the repository at this point in the history
…er timeout error (DEV-2412) #432

If the network connection is very slow, it can happen that the client raises a timeout error, while the API is still processing the request. Because the client has only a temporary identifier of the resource, but no IRI, it is possible to create the same resource multiple times.

The solution is to set the timeout to None, and to wait until the response is available, even if this takes very long.
  • Loading branch information
jnussbaum committed Jul 11, 2023
1 parent 1aeb778 commit b109e3c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/dsp_tools/models/connection.py
Expand Up @@ -122,6 +122,11 @@ def post(self, path: str, jsondata: Optional[str] = None):
:return: Response from server
"""

# timeout must be None,
# otherwise the client can get a timeout error while the API is still processing the request
# in that case, the client's retry will fail, and the response of the original API call is lost
timeout = None

if path[0] != "/":
path = "/" + path
headers = None
Expand All @@ -131,26 +136,26 @@ def post(self, path: str, jsondata: Optional[str] = None):
response = requests.post(
self._server + path,
headers=headers,
timeout=5,
timeout=timeout,
)
else:
response = requests.post(self._server + path, timeout=5)
response = requests.post(self._server + path, timeout=timeout)
else:
if self._token is not None:
headers = {"Content-Type": "application/json; charset=UTF-8", "Authorization": "Bearer " + self._token}
response = requests.post(
self._server + path,
headers=headers,
data=jsondata,
timeout=5,
timeout=timeout,
)
else:
headers = {"Content-Type": "application/json; charset=UTF-8"}
response = requests.post(
self._server + path,
headers=headers,
data=jsondata,
timeout=5,
timeout=timeout,
)
if self._log:
if jsondata:
Expand Down

0 comments on commit b109e3c

Please sign in to comment.