Skip to content

Commit e12be3b

Browse files
authored
Fix infinite loop on corrupted fine-grained cache (#5739)
This hit me when mypyc was causing crashes after having written out part of the cache, but subsequent runs would instead infinite loop.
1 parent 0bee509 commit e12be3b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mypy/build.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,8 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
21452145
if proto_deps is not None:
21462146
TypeState.proto_deps = proto_deps
21472147
elif manager.stats.get('fresh_metas', 0) > 0:
2148+
# Clear the stats so we don't infinite loop because of positive fresh_metas
2149+
manager.stats.clear()
21482150
# There were some cache files read, but no protocol dependencies loaded.
21492151
manager.log("Error reading protocol dependencies cache -- aborting cache load")
21502152
manager.cache_enabled = False

test-data/unit/check-incremental.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,6 +4350,21 @@ import b
43504350
[stale a, b, builtins]
43514351
[rechecked a, b, builtins]
43524352

4353+
[case testIncrementalBustedFineGrainedCache3]
4354+
# flags: --cache-fine-grained
4355+
import a
4356+
import b
4357+
[file a.py]
4358+
[file b.py]
4359+
-- This is a heinous hack, but we simulate having a invalid cache by deleting
4360+
-- the proto deps file.
4361+
[delete ../.mypy_cache/3.6/@proto_deps.meta.json.2]
4362+
[file b.py.2]
4363+
# uh
4364+
-- Every file should get reloaded, since the cache was invalidated
4365+
[stale a, b, builtins]
4366+
[rechecked a, b, builtins]
4367+
43534368
[case testIncrementalWorkingFineGrainedCache]
43544369
# flags: --cache-fine-grained
43554370
# flags2: --cache-fine-grained

0 commit comments

Comments
 (0)