-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Mypy 1.20 crashes on concurrent runs #21136
Description
Crash Report
Mypy 1.20 crashes on concurrent usage because parallel process fight on accessing a sqlite database, at a first glance.
Traceback
version: 1.20.0
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
main()
File "mypy/main.py", line 141, in main
File "mypy/main.py", line 225, in run_build
File "mypy/build.py", line 388, in build
File "mypy/build.py", line 485, in build_inner
File "mypy/build.py", line 3664, in dispatch
File "mypy/build.py", line 3938, in load_graph
File "mypy/build.py", line 2431, in new_state
File "mypy/build.py", line 1717, in find_cache_meta
File "mypy/build.py", line 1527, in _load_ff_file
File "mypy/metastore.py", line 200, in read
File "mypy/metastore.py", line 187, in _query
OperationalError: database is lockedTo Reproduce
A bit difficult to reproduce: it fails regularly on github.
The cause of the failure is pre-commit running 4 concurrent runs of mypy each with about 60 input files. Adding a wrapper script in this run you can see the timings of the run and the list of files passed. Trying the same on my local machine doesn't reproduce because pre-commit decides to pass 20 files per run and the issue is not triggered. I don't see an easy way to configure the batch size used by pre-commit, but it wouldn't be a reliable test anyway.
Looking at the timing of the concurrent processes in the failed run above:
pid: 3032 t0: 1775044872.4642754 started
pid: 3030 t0: 1775044872.4644167 started
pid: 3033 t0: 1775044872.4644256 started
pid: 3034 t0: 1775044872.4649644 started
pid: 3034 tf: 1775044879.1738014 success
pid: 3030 tf: 1775044882.4480267 success
pid: 3032 tf: 1775044884.7451327 failed
pid: 3033 tf: 1775044885.9920673 success
Your Environment
- Mypy version used: 1.20
- Mypy command-line flags:
mypy --pretty --follow-imports=silent --show-traceback file1 file2 ...for long lists of files and with concurrent runs. - Mypy configuration options from
mypy.ini(and other config files): here - Python version used: 3.11.15
- Operating system and version: Ubuntu 24.04