Casting between Puppet Data Types, such as Integer("9"), will cause Puppet Server to retain Puppet::Parser::Catlog objects in memory after requests finish.
See SERVER-2874 for more context and PE reproduction case.
Reproduction Case
- Install Puppet Server on CentOS 7 along with the Java development tools:
yum install -y http://yum.puppetlabs.com/puppet6-release-el-7.noarch.rpm
|
yum install -y puppetserver java-devel
|
source /etc/profile.d/puppet-agent.sh
|
- Install the `pupeptlabs-inifile` module and use it to enable JRuby class reification. This allows Ruby objects, like Puppet::Parser::Compiler, to be identified easily in the Java heap:
puppet module install puppetlabs-inifile
|
|
puppet apply <<'EOF'
|
ini_subsetting { 'Enable JRuby reify.classes':
|
ensure => present,
|
path => '/etc/sysconfig/puppetserver',
|
section => '',
|
key_val_separator => '=',
|
setting => 'JAVA_ARGS',
|
subsetting => '-Djruby.reify.classes',
|
value => '=true',
|
}
|
EOF
|
- Bootstrap the CA, configure the agent, and start the puppetserver service:
puppetserver ca setup
|
puppet config set server $(hostname -f)
|
systemctl start puppetserver
|
- Give the service a trivial catalog to compile:
cat <<'EOF' > /etc/puppetlabs/code/environments/production/manifests/site.pp
|
node default {
|
$string_version = "9"
|
$version = Integer($string_version)
|
}
|
EOF
|
- Run puppet a couple of times:
puppet agent -t
|
puppet agent -t
|
- Check the number of Puppet::Parser::Compiler instances retained in Puppet Server memory:
sudo -u puppet jmap -histo:live $(systemctl show -p MainPID puppetserver|cut -d= -f2)|fgrep 'rubyobj.Puppet.Parser.Compiler'
|
Outcome
After running the agent twice, the puppetserver service is retaining two Compiler instances in memory:
# sudo -u puppet jmap -histo:live $(systemctl show -p MainPID puppetserver|cut -d= -f2)|fgrep 'rubyobj.Puppet.Parser.Compiler'
|
5871: 2 64 rubyobj.Puppet.Parser.Compiler
|
Expected Outcome
No compiler instances should be retained as the compiler is discarded at the end of the request and the -histo:live flag forces a full garbage collection.