Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpack TF plugins in a more atomic way. #33479

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Jul 6, 2023

  1. Unpack TF plugins in a more atomic way.

    The original implementation of plugin cache handling unpacks plugin
    archives in a way that can result in race conditions when multiple
    terraform processes are accessing the same plugin cache. Since the
    archives are being decompressed in chunks and output files are written
    directly to the cache, we observed following manifestations of the issue:
    
    - `text file busy` errors if other terraform processes are already
      running the plugin and another process tries to replace it.
    - various plugin checksum errors triggered likely by simultaneous checksumming
      and rewriting the file.
    
    This PR changes the zip archives with plugins are handled:
    
    1. Instead of writing directly to the target directory,
       `installFromLocalArchive` is now writing to a temporary staging
       directory prefixed with`.temp` that resides in the plugin cache dir
       to ensure this is on the same filesystem.
    2. After unpacking, the directory structure of the staging directory is
       replicated in the `targetDir`. The directories are created as needed
       and any files are moved using `os.Rename`. After this, the staging
       directory is removed.
    3. Since the temporary staging directories can be picked up by
       `SearchLocalDirectory` and make it fail in the situation when they're
       removed during directory traversal, the function has been modified to
       skip any entry that starts with dot.
    
    Signed-off-by: Milan Plzik <[email protected]>
    mplzik committed Jul 6, 2023
    Configuration menu
    Copy the full SHA
    dabf85a View commit details
    Browse the repository at this point in the history