Skip to content

API cache is not write-atomic. #252

Description

@chrisgavin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions