puppetlabs / puppetserver

Server automation framework and application
https://tickets.puppetlabs.com/browse/SERVER
Apache License 2.0
292 stars 235 forks source link

Memory Leak when passing ca_file to Net::HTTP in a custom function #2865

Open mafgh opened 2 months ago

mafgh commented 2 months ago

Describe the Bug

There is a memory leak when using Net::HTTP with ca_file to access a https:// URL in a custom function.

Removing the ca_file parameter, the leak is no longer visible.

Expected Behavior

No memory leak.

Steps to Reproduce

Call something like this in a manifest:

    require 'net/http'
    require 'uri'

    module Puppet::Parser::Functions
            newfunction(:foo, :type => :rvalue)) do |args|
                    uri = URI('https://foo.com')

                    response = Net::HTTP.start(uri.hostname, uri.port,
                            :use_ssl => true,
                            :verify_mode = OpenSSL::SSL::VERIFY_PEER,
                            :ca_file => '/etc/pki/tls/certs/ca-bundle.trust.crt',
                    ) do |http|
                            http.request(request)
                    end

                    return ""
            end
    end                                                                                                      

Environment

RHEL9

puppet-agent-8.6.0-1.el9.x86_64 puppetdb-8.5.0-1.el9.noarch puppetdb-termini-8.5.0-1.el9.noarch puppetserver-8.6.1-1.el9.noarch

openjdk 17.0.9 2023-10-17 LTS

Additional Context

I found https://bugs.ruby-lang.org/issues/15082#note-5, however I don't know if it's related.

The setup has 73 Agents, all with default runinterval. After ~25 hours it would OOM with 10GiB of JVM heap configured.