Skip to content

Commit b70fad5

Browse files
authored
Handle 409s from /step endpoint in Metaflow Service (#258)
With AWS Step Functions, the metaflow task runtime registers the step metadata, which is racy. This PR addresses that by properly handling the 409 response from the metaflow service.
1 parent db11d7e commit b70fad5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

metaflow/metadata/service.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def create_object():
200200
raise
201201

202202
@classmethod
203-
def _request(cls, monitor, path, data=None):
203+
def _request(cls, monitor, path, data=None, retry_409_path=None):
204204
if cls.INFO is None:
205205
raise MetaflowException('Missing Metaflow Service URL. '
206206
'Specify with METAFLOW_SERVICE_URL environment variable')
@@ -231,6 +231,19 @@ def _request(cls, monitor, path, data=None):
231231
else:
232232
if resp.status_code < 300:
233233
return resp.json()
234+
elif resp.status_code == 409 and data is not None:
235+
# a special case: the post fails due to a conflict
236+
# this could occur when we missed a success response
237+
# from the first POST request but the request
238+
# actually went though, so a subsequent POST
239+
# returns 409 (conflict) or we end up with a
240+
# conflict while running on AWS Step Functions
241+
# instead of retrying the post we retry with a get since
242+
# the record is guaranteed to exist
243+
if retry_409_path:
244+
return self._request(retry_409_path)
245+
else:
246+
return
234247
elif resp.status_code != 503:
235248
raise ServiceException('Metadata request (%s) failed (code %s): %s'
236249
% (path, resp.status_code, resp.text),

0 commit comments

Comments
 (0)