[Bug Report] `Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/cache/packwerk/inflections` (issue with cache)
alexevanczuk opened this issue · 1 comments
Description
The cache periodically (rarely) fails in our CI system with the error shown in the screenshots section.
We suspect that the packwerk cache has a race condition when forked processes are initializing the cache independently.
Namely -- after one process has bust the cache and created the cache directory, another process can then bust the cache, after which the original process may try to write the cache contents of inflections.rb
. This can result in the bug:
Errno::ENOENT: No such file or directory @ rb_sysopen - tmp/cache/packwerk/inflections
To Reproduce
We are not able to reliably reproduce this bug.
Expected Behaviour
We expect the cache to not raise an error. From an implementation perspective, we expect tmp/cache/packwerk
to already exist before attempting to write the cache file.
Version Information
- Packwerk: 2.1.0
- Ruby: 2.7.5
Additional Context
Some potential solutions we're looking at to solve this issue:
- We can initialize
Cache
within the parent process to ensure that the call toFileUtils.rm_fr
is only run once at the start. This is what we went with in this PR: #183 - Alternatively, we can also drop the
rm_fr
entirely, and use a strategy that hashes based on the digest of the current inflections.