online-judge-tools / api-client

API client to develop tools for competitive programming
MIT License
62 stars 18 forks source link

`oj-api get-problem https://judge.yosupo.jp/problem/xxx` fails if it's executed in parallel #45

Open to-omer opened 4 years ago

to-omer commented 4 years ago

あまり想定されない使い方かもしれませんが、一応。 Library-Checkerの問題を並列に取得しようとするとエラーが発生します。

OS: Windos 10 Python: 3.8 online-judge-tools: 10.0.8 oj-api get-problem https://judge.yosupo.jp/problem/aplusb を同時に実行するとエラーが出る 以下実行結果

$ oj-api get-problem https://judge.yosupo.jp/problem/aplusb
INFO:root:sleep 1.000000 sec
INFO:onlinejudge._implementation.logging:[x] problem recognized: LibraryCheckerProblem.from_url('https://judge.yosupo.jp/problem/aplusb'): https://judge.yosupo.jp/problem/aplusb
INFO:onlinejudge._implementation.logging:[-] unknown contest: https://judge.yosupo.jp/problem/aplusb
INFO:onlinejudge._implementation.logging:[x] service recognized: LibraryCheckerService.from_url('https://judge.yosupo.jp/'): https://judge.yosupo.jp/problem/aplusb
INFO:onlinejudge._implementation.logging:[x] load cookie from: C:\Users\username\AppData\Local\online-judge-tools\online-judge-tools\cookie.jar
git version 2.21.0.windows.1
INFO:onlinejudge._implementation.logging:[x] $ git -C C:\Users\username\AppData\Local\online-judge-tools\online-judge-tools\Cache\library-checker-problems pull
error: cannot lock ref 'refs/remotes/origin/master': is at 2ae8b8d8f84069bd8a1b216f0d6a960f0b3d9859 but expected 95f8a5cbbf51de68e67c3662672d6e34a585fb6f
From https://github.com/yosupo06/library-checker-problems
 ! 95f8a5c..2ae8b8d  master     -> origin/master  (unable to update local ref)
ERROR:root:Command '['git', '-C', 'C:\\Users\\username\\AppData\\Local\\online-judge-tools\\online-judge-tools\\Cache\\library-checker-problems', 'pull']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "c:\path-to-python-dir\lib\site-packages\onlinejudge_api\main.py", line 236, in main
    result = get_problem.main(problem, is_system=parsed.system, is_full=parsed.full, is_compatibility=parsed.compatibility, session=session)
  File "c:\path-to-python-dir\lib\site-packages\onlinejudge_api\get_problem.py", line 294, in main
    tests = problem.download_system_cases(session=session)
  File "c:\path-to-python-dir\lib\site-packages\onlinejudge\service\library_checker.py", line 84, in download_system_cases
    self._generate_test_cases_in_cloned_repository()
  File "c:\path-to-python-dir\lib\site-packages\onlinejudge\service\library_checker.py", line 92, in _generate_test_cases_in_cloned_repository
LibraryCheckerService._update_cloned_repository()
  File "c:\path-to-python-dir\lib\site-packages\onlinejudge\service\library_checker.py", line 66, in _update_cloned_repository
    subprocess.check_call(['git', '-C', str(path), 'pull'], stdout=sys.stderr, stderr=sys.stderr)
  File "c:\path-to-python-dir\lib\subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', '-C', 'C:\\Users\\username\\AppData\\Local\\online-judge-tools\\online-judge-tools\\Cache\\library-checker-problems', 'pull']' returned non-zero exit status 1.

ちなみに何度か試しましたがほとんど再現しませんでした (代わりにLibrary-Checkerのgenerate.py呼び出し中に衝突して死にましたが)

kmyk commented 4 years ago

想定していませんでした。並列で処理すると壊れます。 報告自体はありがたいですし、いつかは直したいバグですが、あまり優先度は高くないです。プルリクを出してもらえばすぐ直りますが、単純に難易度が高いのでおすすめはしません。

バグではあるが優先度が低い理由:

kmyk commented 4 years ago

(ところで、そもそも並列実行はあまりおすすめできません。下手をするとサーバ側に DoS 攻撃 と認識されてトラブルに巻き込まれる可能性があります)

to-omer commented 4 years ago

rustからoj-apiを呼び出してライブラリのテストをしようとしていましたが、rustではテストがデフォルトで並列に実行されるのでこのバグを踏んでしまった、というのが経緯でした。 generate.py のことも考えると、おとなしく手元で同時呼び出ししないように排他制御するのがよさそうです。