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

Conversation

joshcooper
Copy link
Contributor

@joshcooper joshcooper commented Feb 26, 2021

Environment state for an expired environment leaked into newly created instances, if the cached loader's list or get_conf methods had been called prior to expiration. This doesn't occur if get is called, because the environment is cached, and the per-environment settings are cleared when clear or clear_all are called.

When using versioned code deploys, list and get could return different modulepaths for the same environment between the time new code was deployed and when the environment was expired. Now the "list" method returns the cached environment (if there is one) or the newly created environment object. In the latter case, we cache the environment, so it can be cleared if/when clear or clear_all are called for that environment.

@justinstoller
Copy link
Member

👍 This seems like a good approach

@joshcooper joshcooper force-pushed the envconf_caching_10942 branch from c046281 to 552f127 Compare February 27, 2021 01:33
Our `include_in_any_order` matcher predates `contain_exactly`.
@joshcooper joshcooper force-pushed the envconf_caching_10942 branch from 552f127 to 54b23f4 Compare March 4, 2021 00:17
Environment state for an expired environment leaked into newly created
instances, if the cached loader's `list` or `get_conf` methods had been called
prior to expiration.

This doesn't occur if `get` is called, because the environment is cached, and
the per-environment settings are cleared when `clear` or `clear_all` are called.

Clear per-environments settings prior to creating the environment instance.
@joshcooper joshcooper force-pushed the envconf_caching_10942 branch 2 times, most recently from 83a56a3 to a8b4e6c Compare March 4, 2021 00:29
When using versioned code deploys, `list` and `get` could return different
modulepaths for the same environment between the time new code was deployed and
when the environment was expired. Now the "list" method returns the cached
environment (if there is one) or the newly created environment object. In the
latter case, we cache the environment, so it can be cleared if/when clear or
clear_all are called for that environment.
@joshcooper joshcooper force-pushed the envconf_caching_10942 branch from a8b4e6c to 8d569e8 Compare March 4, 2021 00:45
@@ -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:

@joshcooper joshcooper marked this pull request as ready for review March 5, 2021 00:40
@joshcooper joshcooper requested review from a team March 5, 2021 00:40

@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

@joshcooper
Copy link
Contributor Author

jenkins please test this with servertests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants