Jira (PUP-10659) Data Type casts cause Puppet Server to retain Compiler instances

22 views
Skip to first unread message

Charlie Sharpsteen (Jira)

unread,
Sep 4, 2020, 12:10:03 PM9/4/20
to puppe...@googlegroups.com
Charlie Sharpsteen updated an issue
 
Puppet / Bug PUP-10659
Data Type casts cause Puppet Server to retain Compiler instances
Change By: Charlie Sharpsteen
Summary: Data Type casts case cause Puppet Server to retain Compiler instances
Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Charlie Sharpsteen (Jira)

unread,
Sep 4, 2020, 12:51:03 PM9/4/20
to puppe...@googlegroups.com
Charlie Sharpsteen commented on Bug PUP-10659
 
Re: Data Type casts cause Puppet Server to retain Compiler instances

The cause of this appears to be two behaviors in the following section of code in lib/puppet/functions/new.rb:

def new_function_for_type(t, scope)
  @new_function_cache ||= Hash.new() {|hsh, key| hsh[key] = key.new_function.new(scope, loader) }
  @new_function_cache[t]
end

https://github.com/puppetlabs/puppet/blob/6.18.0/lib/puppet/functions/new.rb

This maintains a cache of constructor functions for each datatype: new String, new Integer, etc. The two issues are:

  • The cache is a Hash instance with a lambda function that creates constructor functions as they are requested. This lambda closes over the Compiler scope value passed the first time new() is called, which keeps that scope in memory.

Aside from the memory leak, it seems wrong to be using the scope of the first Compiler that happens to call new() to provide data for subsequent compilations.

Charlie Sharpsteen (Jira)

unread,
Sep 4, 2020, 1:37:04 PM9/4/20
to puppe...@googlegroups.com

The following re-factor of the new_function_for method appears to solve the leak:

def new_function_for_type(t, scope)
  @new_function_cache ||= {}
 
  if ! @new_function_cache.key?(t)
    @new_function_cache[t] = t.new_function.new(nil, loader)
  end
 
  @new_function_cache[t]
end

The main functional change is passing nil when creating the constructor function instead of passing scope. It seems like this should be fine as functions will fall back to using the current Compiler's global scope if the value previously populated by scope is referenced:

https://github.com/puppetlabs/puppet/blob/6.18.0/lib/puppet/pops/functions/function.rb#L78-L79

Also, having constructor functions created in subsequent compilations be dependent on the scope of the first Compiler ever created seems like it would be bug.

Charlie Sharpsteen (Jira)

unread,
Sep 4, 2020, 3:16:04 PM9/4/20
to puppe...@googlegroups.com

Initializing the constructor functions with the current compilers scope seems to echo PUP-6582. This commit in Puppet changed most function initialization to use nil as the closure scope:

https://github.com/puppetlabs/puppet/commit/915d934ad06

Unless new() is special in some way, it seems like the same rationale would apply.

Henrik Lindberg (Jira)

unread,
Sep 5, 2020, 12:30:04 PM9/5/20
to puppe...@googlegroups.com

Austin Boyd (Jira)

unread,
Sep 8, 2020, 7:03:03 PM9/8/20
to puppe...@googlegroups.com

Austin Boyd (Jira)

unread,
Sep 8, 2020, 7:03:03 PM9/8/20
to puppe...@googlegroups.com
Austin Boyd updated an issue
Change By: Austin Boyd
Zendesk Ticket Count: 1
Zendesk Ticket IDs: 40701

Mihai Buzgau (Jira)

unread,
Sep 9, 2020, 4:26:03 AM9/9/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Sep 9, 2020, 4:27:03 AM9/9/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Sep 9, 2020, 4:27:04 AM9/9/20
to puppe...@googlegroups.com

Gabriel Nagy (Jira)

unread,
Sep 10, 2020, 9:48:05 AM9/10/20
to puppe...@googlegroups.com

Mihai Buzgau (Jira)

unread,
Sep 16, 2020, 5:57:03 AM9/16/20
to puppe...@googlegroups.com
Mihai Buzgau updated an issue
Change By: Mihai Buzgau
Sprint: NW - 2020-09-16 , NW - 2020-09-30

Gabriel Nagy (Jira)

unread,
Sep 17, 2020, 2:51:04 AM9/17/20
to puppe...@googlegroups.com
Gabriel Nagy updated an issue
Change By: Gabriel Nagy
Fix Version/s: PUP 6.19.0
Fix Version/s: PUP 5.5.22

Claire Cadman (Jira)

unread,
Oct 12, 2020, 9:16:03 AM10/12/20
to puppe...@googlegroups.com
Claire Cadman updated an issue
Change By: Claire Cadman
Labels: doc_reviewed jira_escalated

zendesk.jira (Jira)

unread,
Nov 10, 2020, 11:43:03 AM11/10/20
to puppe...@googlegroups.com
zendesk.jira updated an issue
Change By: zendesk.jira
Zendesk Ticket Count: 1 2
Zendesk Ticket IDs: 40701 ,41223
Reply all
Reply to author
Forward
0 new messages