Skip to content

Commit

Permalink
Fix partial binpack upload
Browse files Browse the repository at this point in the history
Ensure that when the monty datagen process encounters an error, neither the result nor the binpack is uploaded, and the return code is reported to the server
  • Loading branch information
Viren6 committed Aug 24, 2024
1 parent f9623e5 commit bc3d284
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion server/montytest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
according to the route/URL mapping defined in `__init__.py`.
"""

WORKER_VERSION = 20
WORKER_VERSION = 21


@exception_view_config(HTTPException)
Expand Down
35 changes: 24 additions & 11 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,27 +1519,40 @@ def run_datagen_games(
close_fds=not IS_WINDOWS,
) as p:
try:
# Wait for the process to complete
print("Waiting for datagen to finish ... ", flush=True)
p.wait(timeout=FASTCHESS_KILL_TIMEOUT)

if p.returncode != 0:
print(
f"Datagen process exited with code {p.returncode}. Removing binpack.",
flush=True,
)
if games_file.exists():
games_file.unlink()
raise WorkerException(
f"Datagen process exited with non-zero return code: {p.returncode}"
)

# Call parse_datagen_output only if process succeeded
parse_datagen_output(p, tc_factor, result, remote, current_state)
except:
except subprocess.TimeoutExpired:
print("timeout", flush=True)
kill_process(p)
raise WorkerException("Datagen process timed out and was killed.")
except Exception:
# Remove the binpack on exception
print("Removing binpack", flush=True)
if games_file.exists():
games_file.unlink()
else:
print("Datagen finished", flush=True)
finally:
# We nicely ask cutechess-cli to stop.
# We nicely ask the monty datagen process to stop.
try:
send_sigint(p)
except Exception as e:
print("\nException in send_sigint:\n", e, sep="", file=sys.stderr)
# now wait...
print("\nWaiting for datagen to finish ... ", end="", flush=True)
try:
p.wait(timeout=FASTCHESS_KILL_TIMEOUT)
except subprocess.TimeoutExpired:
print("timeout", flush=True)
kill_process(p)
else:
print("done", flush=True)
except (OSError, subprocess.SubprocessError) as e:
print(
"Exception starting datagen:\n",
Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 20, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "VgVVa7f6bdHWJU/uKVcAGApcegP/fZwgV45PLSbfGTHUmc66F51hGbGBZZRvhRMM", "games.py": "jdCHJDCixQ9Fa138HXoUcOvvHEAHO7BWq/3XUmr0GYHQ/zlRYyjuSueEQPxkMTg9"}
{"__version": 21, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "n3cgpMhYBEOQVvXl+NNEv6YCsbWqbH0jqiDaI5g0yoCot8fEbThrenDdYNMkI+oq", "games.py": "MyB/5iO/R0PEXQOB+ZhACzieuTTRnuGE3gbzvul35gewqG/t58EztU0fY0FYCzOA"}
2 changes: 1 addition & 1 deletion worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
MIN_CARGO_MAJOR = 1
MIN_CARGO_MINOR = 77

WORKER_VERSION = 20
WORKER_VERSION = 21
FILE_LIST = ["updater.py", "worker.py", "games.py"]
HTTP_TIMEOUT = 30.0
INITIAL_RETRY_TIME = 15.0
Expand Down

0 comments on commit bc3d284

Please sign in to comment.