Jira (PUP-11129) Cached environment may not be deleted if the directory is removed

4 views
Skip to first unread message

Josh Cooper (Jira)

unread,
Jun 28, 2021, 8:25:02 PM6/28/21
to puppe...@googlegroups.com
Josh Cooper created an issue
 
Puppet / Bug PUP-11129
Cached environment may not be deleted if the directory is removed
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2021/06/28 5:24 PM
Priority: Normal Normal
Reporter: Josh Cooper

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

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Ciprian Badescu (Jira)

unread,
Jun 29, 2021, 10:34:02 AM6/29/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Jun 29, 2021, 10:34:02 AM6/29/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Jun 30, 2021, 4:44:01 AM6/30/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Jun 30, 2021, 4:44:02 AM6/30/21
to puppe...@googlegroups.com

Luchian Nemes (Jira)

unread,
Jun 30, 2021, 4:45:02 AM6/30/21
to puppe...@googlegroups.com
Luchian Nemes commented on Bug PUP-11129
 
Re: Cached environment may not be deleted if the directory is removed

After this fix, we should also update the rspec tests from https://github.com/puppetlabs/puppet/pull/8655/commits/0d8c1d5a1b70674450fd80e919d198ab919bcb46 that use `instance_variable_get` to check this Puppet::Environments::Cached#list instead for the expects.

Gheorghe Popescu (Jira)

unread,
Jun 30, 2021, 8:23:01 AM6/30/21
to puppe...@googlegroups.com

Gheorghe Popescu (Jira)

unread,
Jun 30, 2021, 11:12:01 AM6/30/21
to puppe...@googlegroups.com
Gheorghe Popescu commented on Bug PUP-11129
 
Re: Cached environment may not be deleted if the directory is removed

https://github.com/puppetlabs/puppet/pull/8663/files

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

Josh Cooper (Jira)

unread,
Jul 2, 2021, 12:34:03 PM7/2/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jul 2, 2021, 12:35:01 PM7/2/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jul 7, 2021, 7:22:02 PM7/7/21
to puppe...@googlegroups.com

Claire Cadman (Jira)

unread,
Jul 13, 2021, 7:50:04 AM7/13/21
to puppe...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages