Skip to content

(PUP-10942) Don't leak environment state when creating a new instance #8523

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

Merged
merged 5 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/puppet/environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ def get_conf(name)
private

def create_environment(name)
# interpolated modulepaths may be cached from prior environment instances
Puppet.settings.clear_environment_settings(name)

env_symbol = name.intern
setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode)
env = Puppet::Node::Environment.create(
Expand Down Expand Up @@ -350,7 +353,19 @@ def initialize(loader)

# @!macro loader_list
def list
@loader.list
# Evict all that have expired, in the same way as `get`
clear_all_expired

@loader.list.map do |env|
name = env.name
old_entry = @cache[name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's nothing here we need to worry about regarding symbols vs strings?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I walked through it and I guess strings vs symbols just worries me in general. But I don't see where it would have an effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the existing behavior of using whatever name is passed to get. Here we check if the name is cached and if not, we pass the name to add_entry and it stores it under that key. Similarly, if we're asked to clear a specific entry, we just use that name.

I agree the string vs symbol thing could bite us, so I filed https://tickets.puppetlabs.com/browse/PUP-10955

if old_entry
old_entry.value
else
add_entry(name, entry(env))
env
end
end
end

# @!macro loader_search_paths
Expand Down
9 changes: 8 additions & 1 deletion lib/puppet/file_system/memory_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ def self.a_missing_file(path)
new(path, :exist? => false, :executable? => false)
end

def self.a_missing_directory(path)
new(path,
:exist? => false,
:executable? => false,
:directory? => true)
end

def self.a_regular_file_containing(path, content)
new(path, :exist? => true, :executable? => false, :content => content)
end
Expand All @@ -18,7 +25,7 @@ def self.an_executable(path)
def self.a_directory(path, children = [])
new(path,
:exist? => true,
:excutable? => true,
:executable? => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:ohmy:

:directory? => true,
:children => children)
end
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/settings/environment_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def self.load_from(path_to_env, global_module_path)
section = config.sections[:main]
rescue Errno::ENOENT
# environment.conf is an optional file
Puppet.debug { "Path to #{path_to_env} does not exist, using default environment.conf" }
end

new(path_to_env, section, global_module_path)
Expand Down
4 changes: 1 addition & 3 deletions spec/integration/indirector/direct_file_server_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'spec_helper'
require 'matchers/include'

require 'puppet/indirector/file_content/file'
require 'puppet/indirector/file_metadata/file'
Expand Down Expand Up @@ -30,7 +29,6 @@

describe Puppet::Indirector::DirectFileServer, " when interacting with FileServing::Fileset and the model" do
include PuppetSpec::Files
include Matchers::Include

matcher :file_with_content do |name, content|
match do |actual|
Expand All @@ -52,7 +50,7 @@
terminus = Puppet::Indirector::FileContent::File.new
request = terminus.indirection.request(:search, Puppet::Util.path_to_uri(path).to_s, nil, :recurse => true)

expect(terminus.search(request)).to include_in_any_order(
expect(terminus.search(request)).to contain_exactly(
file_with_content(File.join(path, "one"), "one content"),
file_with_content(File.join(path, "two"), "two content"),
directory_named(path))
Expand Down
27 changes: 0 additions & 27 deletions spec/lib/matchers/include.rb

This file was deleted.

32 changes: 0 additions & 32 deletions spec/lib/matchers/include_spec.rb

This file was deleted.

Loading