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

An environment may be reloaded during a single compilation

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • None
    • PUP 6.25.0, PUP 7.10.0
    • None
    • Bug Fix
    • Hide
      Previously, Puppet Server could expire an environment and reload it, while it was being used to compile a catalog. If translations were enabled (Puppet[:disable_i18n] set to false), then compilation could fail. Now Puppet Server prevents environments from being reloaded while they are in use, and instead reloads the environment the next time it is requested.
      Show
      Previously, Puppet Server could expire an environment and reload it, while it was being used to compile a catalog. If translations were enabled (Puppet[:disable_i18n] set to false), then compilation could fail. Now Puppet Server prevents environments from being reloaded while they are in use, and instead reloads the environment the next time it is requested.
    • Needs Assessment

    Description

      The environment cache's keys may be strings or symbols, so you can end up with same environment cached under two different names (see PUP-10955). We tried fixing the issue, but it turns out we're currently relying on the symbol/string confusion to prevent an environment from being reloaded during a compilation.

      For example, given this script:

      require 'puppet'
      Locale.current = 'ja_JP'
      Puppet.initialize_settings
      Puppet::GettextConfig.setup_locale
      Puppet::Resource::Catalog.indirection.terminus_class = :compiler
      Puppet[:log_level] = 'debug'
      Puppet::Util::Log.newdestination(:console)
       
      Puppet::ApplicationSupport.push_application_context(Puppet::Util::RunMode[:server])
      catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], environment: :production)
      puts catalog.resource(:notify, 'happy')[:message]
      

      Results in the following:

      $ bundle exec puppet module install eputnam-i18ndemo
      $ bundle exec ruby envs.rb
      ...
      Debug: Loaded translations for puppetlabs-stdlib.
      Debug: Loaded translations for eputnam-i18ndemo.
      Debug: Evicting cache entry for environment 'production'
      Debug: Deleted current text domain :production: true
      Debug: Path to /home/josh/.puppetlabs/etc/code/environments/production does not exist, using default environment.conf
      ...`
      Notice: Compiled catalog for localhost in environment production in 0.02 seconds
      --*IT'S HAPPY FUN TIME*--
      yppah
      --*IT'S HAPPY FUN TIME*--
      

      Note the translations are loaded, but the environment is cleared and the text domain is deleted prior to compilation, so we end up with the non-localized message IT'S HAPPY FUN TIME.

      Changing the environment parameter to a string, prevents the environment from being cleared:

      catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], environment: 'production')
      

      And we get the localized message:

      --*eputnam-i18ndemo function: それは楽しい時間です*--
      yppah
      --*eputnam-i18ndemo function: それは楽しい時間です*--
      

      We should be explicit about not reloading an environment during a single compilation. If environment_timeout=0, then the environment should be reloaded during the next compilation (or any indirected request).

      Also maggie says it's important for versioned code deploys to keep the same environment object throughout a compile.

      Attachments

        Issue Links

          Activity

            People

              josh Josh Cooper
              josh Josh Cooper
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Zendesk Support