The cache's store method is not atomic. It is protected by a mutex, but this mutex only prevents concurrent in-process writes. If multiple invocations of the gh CLI are run in parallel then two concurrent writes to the same cache file can occur, corrupting the cache.
Similarly if a process dies mid-write then a partially written file can end up in the cache.
A simple fix for this would be to make the cache write atomic by writing to a temporary file and then doing an atomic move to overwrite the cache entry.
The cache's
storemethod is not atomic. It is protected by a mutex, but this mutex only prevents concurrent in-process writes. If multiple invocations of theghCLI are run in parallel then two concurrent writes to the same cache file can occur, corrupting the cache.Similarly if a process dies mid-write then a partially written file can end up in the cache.
A simple fix for this would be to make the cache write atomic by writing to a temporary file and then doing an atomic move to overwrite the cache entry.