Skip to content

Commit 358679d

Browse files
robertnurnbergppigazzini
authored andcommitted
feat: check integrity of cached binaries
Raise worker version to 295 (also server side) Using suggestion by @MinetaS Fixes official-stockfish#2389
1 parent 5745e48 commit 358679d

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

server/fishtest/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
according to the route/URL mapping defined in `__init__.py`.
3737
"""
3838

39-
WORKER_VERSION = 294
39+
WORKER_VERSION = 295
4040

4141

4242
@exception_view_config(HTTPException)

worker/games.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,20 @@ def create_environment():
808808
return env, env_hash
809809

810810

811+
def engine_is_healthy(path: Path, timeout_s: float = 5.0):
812+
try:
813+
r = subprocess.run(
814+
[str(path), "bench", "16", "1", "5", "default", "depth"],
815+
stdout=subprocess.DEVNULL,
816+
stderr=subprocess.DEVNULL,
817+
check=False,
818+
timeout=timeout_s,
819+
)
820+
return r.returncode == 0
821+
except (OSError, subprocess.SubprocessError):
822+
return False
823+
824+
811825
def setup_engine(
812826
testing_dir,
813827
remote,
@@ -824,10 +838,19 @@ def setup_engine(
824838
engine_path = (testing_dir / (engine_name + "-old")).with_suffix(EXE_SUFFIX)
825839
engine_path_native = (testing_dir / engine_name).with_suffix(EXE_SUFFIX)
826840
for path in (engine_path_native, engine_path):
827-
if path.exists():
841+
if not path.exists():
842+
continue
843+
844+
if engine_is_healthy(path):
828845
update_atime(path)
829846
return path
830847

848+
print(f"Removing invalid engine {path}")
849+
try:
850+
path.unlink()
851+
except Exception as e:
852+
raise WorkerException(f"Failed to remove cached engine {path}:\n{e}")
853+
831854
"""Download and build sources in a temporary directory then move exe as engine_path"""
832855
worker_dir = testing_dir.parent
833856
tmp_dir = Path(tempfile.mkdtemp(dir=worker_dir))

worker/sri.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"__version": 294, "updater.py": "eDDBPKA/vrTCadgtEJFdL06vSoiysF0JhiHKdEnjQv3zS4kfdOAqnco/DJpDWbvh", "worker.py": "3yyZwB+V8zbs7IwsuUWniKWC2zL2J2fpMfENAvRsanwVtVqFvtw4KcN4BZupJvnV", "games.py": "VdcZIM4EsM66WnU4FzIlHOWRrsJrgpxiFVyN9rG4KMdNGmQsZ6JbgAJUrvXOOMJx"}
1+
{"__version": 295, "updater.py": "eDDBPKA/vrTCadgtEJFdL06vSoiysF0JhiHKdEnjQv3zS4kfdOAqnco/DJpDWbvh", "worker.py": "LFWwPl6NeiFOWQzj5TPiMPuP0wdaS22jLJMa2PLyhl9F8rSemFPNq3Rpk7tKf5uk", "games.py": "sbNzCoZRY4NoJoOYMVevv0JRbfRWYndkukrXe2krhD6h3ktmo2YL/Z5NTJyY96iL"}

worker/worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474
FASTCHESS_SHA = "66cac47f06dc1a09d3d1865cdbf560a7814f82ea"
7575

76-
WORKER_VERSION = 294
76+
WORKER_VERSION = 295
7777
FILE_LIST = ["updater.py", "worker.py", "games.py"]
7878
HTTP_TIMEOUT = 30.0
7979
INITIAL_RETRY_TIME = 15.0

0 commit comments

Comments
 (0)