If you're getting a
Cannot allocate memory error in
puppetserver.log or in the output of a Puppet run, you might need to remove backticks from external commands in your Ruby functions.
Error messages and logs
Evaluation Error: Error while evaluating a Function Call, Cannot allocate memory
When backticks are used in Ruby functions, JRuby emulates Ruby's fork-exec behavior, creating a new copy of the JVM process. This is resource intensive and might result in a memory allocation error.
Version and installation information
PE version: All supported
In this case, replacing backticks in functions with
Puppet::Util::Execution.execute in Ruby functions prevents this error. Using
Puppet::Util::Execution.execute ensures that spawning of external processes is done in a lightweight manner.
For example, change:
result = `<EXTERNAL COMMAND>`
require 'puppet' result = Puppet::Util::Execution.execute("<EXTERNAL COMMAND>")
This error can also occur if an external command yields too much output. Depending on the command, you can manage the output using
IO#popen or by having the command write to a file.
Learn more about the issue: https://tickets.puppetlabs.com/browse/SERVER-2021