contest: retry when unable to load input files - #90
Conversation
|
I thought we had some "atomic update" method for updating the JSON files. Does it still race? Maybe some files are missing using that atomic update API? |
|
From what I understood, Lines 26 to 37 in 95a2926 It looks like there is a very small window where the file can be empty. |
|
That's the one, it should be doing an "atomic" write, write to a temp file and rename it overriding the existing file, instead of dumping directly to the output. |
d8171b9 to
73c9215
Compare
The contest service was unable to load the 'branch_info' input file
twice recently. Probably because it was being updated:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Instead of catching the error and retry later, this file can be written
atomically by using a tmp file and renaming it to the expected name.
That's the recommended way [1]:
os.rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None):
(...)
If both are files, dst will be replaced silently if the user has
permission. (...) If successful, the renaming will be an atomic
operation (this is a POSIX requirement).
Link: https://docs.python.org/3/library/os.html#os.rename [1]
Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
73c9215 to
8f32c6c
Compare
Indeed, better with an atomic write! I just fixed that. |
The contest service was unable to load the 'branch_info' input file twice yesterday. Probably because it was being updated:
Catch the error, and retry max 4 more times with the same delay.