Skip to content

Commit 769b4f8

Browse files
committed
contest: collector: don't crash when remote has invalid JSON
Remotes sometimes serve us invalid JSON files, usually due to race conditions between writing and us fetching. Skip those, we will retry on the next poll. And in case of persistent failure we'll not report anything and contest will report that remote is dead. Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 67d300d commit 769b4f8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

contest/results-collector.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,19 @@ def write_json_atomic(path, data):
276276

277277
def fetch_remote_run(fetcher, remote, run_info, remote_state):
278278
r = requests.get(run_info['url'])
279-
data = json.loads(r.content.decode('utf-8'))
279+
try:
280+
data = json.loads(r.content.decode('utf-8'))
281+
except json.decoder.JSONDecodeError:
282+
print('WARN: Failed to decode results from remote:', remote['name'],
283+
'invalid JSON at', run_info['url'])
284+
return False
280285

281286
fetcher.insert_real(remote, data)
282287

283288
file = os.path.join(remote_state['dir'], os.path.basename(run_info['url']))
284289
with open(file, "w") as fp:
285290
json.dump(data, fp)
291+
return True
286292

287293

288294
def fetch_remote(fetcher, remote, seen):
@@ -291,7 +297,7 @@ def fetch_remote(fetcher, remote, seen):
291297
try:
292298
manifest = json.loads(r.content.decode('utf-8'))
293299
except json.decoder.JSONDecodeError:
294-
print('Failed to decode manifest from remote:', remote['name'])
300+
print('WARN: Failed to decode manifest from remote:', remote['name'])
295301
return
296302
remote_state = seen[remote['name']]
297303

@@ -305,8 +311,8 @@ def fetch_remote(fetcher, remote, seen):
305311
continue
306312

307313
print('Fetching run', run['branch'])
308-
fetch_remote_run(fetcher, remote, run, remote_state)
309-
fetcher.fetched = True
314+
if fetch_remote_run(fetcher, remote, run, remote_state):
315+
fetcher.fetched = True
310316

311317
with open(os.path.join(remote_state['dir'], 'results.json'), "w") as fp:
312318
json.dump(manifest, fp)

0 commit comments

Comments
 (0)