Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-11129

Cached environment may not be deleted if the directory is removed

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: PUP 6.24.0, PUP 7.9.0
    • Component/s: None
    • Labels:
    • Template:
      PUP Bug Template
    • Team:
      Night's Watch
    • Story Points:
      2
    • Sprint:
      NW - 2021-07-14
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      List environments is now evicting cached environments that are no longer on disk.
    • QA Risk Assessment:
      Needs Assessment

      Description

      Puppet::Environments::Cached#list returns environments that exist on disk and either caches the entry or updates its ttl. However, if an environment is in the cache, but is no longer on disk, then it is not removed from the cache. This shouldn't be an issue with r10k/code manager, because they explicitly delete the environment or all environments after purging the directory. But it could lead to consistency problems if the REST request never occurs or fails. The following shows how after the environment is deleted, it is not returned from the list method, yet it is still cached:

      require 'puppet'
      Puppet.initialize_settings(['--environment_timeout', 'unlimited'])
      Puppet::Util::Log.newdestination(:console)
       
      name = "test#{Process.pid}"
      testdir = File.join(Puppet[:environmentpath], name)
      FileUtils.mkdir_p(testdir)
       
      Puppet::ApplicationSupport.push_application_context(Puppet::Util::RunMode[:user])
       
      envs = Puppet.lookup(:environments)
      envs.get!(:production)
      envs.get!(name)
       
      puts "Listed #{envs.list.map(&:name).join(', ')} environments"
       
      FileUtils.rm_rf(testdir)
      puts "Deleted #{name} environment"
       
      puts "Listed #{envs.list.map(&:name).join(', ')} environments"
      puts "Cached #{envs.instance_variable_get(:@cache).keys.join(', ')} environments"
      

      ❯ ls  ~/.puppetlabs/etc/code/environments/
      production/
       
      ❯ bx ruby envs.rb                         
      Listed test2597598, production environments
      Deleted test2597598 environment
      Listed production environments
      Cached production, test2597598 environments
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              gheorghe.popescu Gheorghe Popescu
              Reporter:
              josh Josh Cooper
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Zendesk Support