Jira (PUP-11329) Attempt to redefine entity error on agent if plugins are reloaded

98 views
Skip to first unread message

Josh Cooper (Jira)

unread,
Oct 26, 2021, 12:04:04 PM10/26/21
to puppe...@googlegroups.com
Josh Cooper created an issue
 
Puppet / Bug PUP-11329
Attempt to redefine entity error on agent if plugins are reloaded
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2021/10/26 9:03 AM
Priority: Normal Normal
Reporter: Josh Cooper

If an autoloaded type or provider is loaded prior to pluginsync and then modified during pluginsync, puppet will attempt to reload changed files, which can trigger the "Attempt to redefine entity" error. This is different (I think) than the issue described in SERVER-3034, where the entity is reloaded during catalog compilation.

To reproduce from source:

require 'puppet'
Puppet.initialize_settings
Puppet::Util::Log.newdestination(:console)
 
run_mode = Puppet::Util::RunMode[:agent]
Puppet::ApplicationSupport.push_application_context(run_mode)
 
env = Puppet.lookup(:environments).get!(Puppet[:environment])
Puppet.push_context(current_environment: env, loaders: Puppet::Pops::Loaders.new(env, true))
 
type = Puppet::Type.type(:exec)
loader = type.providerloader
 
FileUtils.touch(File.join(Dir.pwd, "lib/puppet/type/exec.rb"))
pp loader.class.reload_changed(env)

$ git rev-parse HEAD
4c0b8e038f4eff680c25cd5ab7874755b7f8966e
$ bx ruby redefine.rb
Error: Could not autoload puppet/type/exec: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/exec'. Originally set at file:///home/josh/work/puppet/lib/puppet/type/exec.rb?line=2.
Traceback (most recent call last):
	16: from t.rb:15:in `<main>'
	15: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:98:in `reload_changed'
	14: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:98:in `each'
	13: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:100:in `block in reload_changed'
	12: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:78:in `load_file'
	11: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:78:in `load'
	10: from /home/josh/work/puppet/lib/puppet/type/exec.rb:1:in `<top (required)>'
	 9: from /home/josh/work/puppet/lib/puppet/type/exec.rb:2:in `<module:Puppet>'
	 8: from /home/josh/work/puppet/lib/puppet/metatype/manager.rb:73:in `newtype'
	 7: from /home/josh/work/puppet/lib/puppet/concurrent/lock.rb:10:in `synchronize'
	 6: from /home/josh/work/puppet/lib/puppet/metatype/manager.rb:131:in `block in newtype'
	 5: from /home/josh/work/puppet/lib/puppet/pops/loaders.rb:154:in `register_runtime3_type'
	 4: from /home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:75:in `set_entry'
	 3: from /home/josh/work/puppet/lib/puppet/pops/loader/loader.rb:153:in `synchronize'
	 2: from /home/josh/work/puppet/lib/puppet/concurrent/lock.rb:10:in `synchronize'
	 1: from /home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:79:in `block in set_entry'
/home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:135:in `fail_redefine': Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/exec'. Originally set at file:///home/josh/work/puppet/lib/puppet/type/exec.rb?line=2. (ArgumentError)
	16: from t.rb:15:in `<main>'
	15: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:98:in `reload_changed'
	14: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:98:in `each'
	13: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:100:in `block in reload_changed'
	12: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:78:in `load_file'
	11: from /home/josh/work/puppet/lib/puppet/util/autoload.rb:78:in `load'
	10: from /home/josh/work/puppet/lib/puppet/type/exec.rb:1:in `<top (required)>'
	 9: from /home/josh/work/puppet/lib/puppet/type/exec.rb:2:in `<module:Puppet>'
	 8: from /home/josh/work/puppet/lib/puppet/metatype/manager.rb:73:in `newtype'
	 7: from /home/josh/work/puppet/lib/puppet/concurrent/lock.rb:10:in `synchronize'
	 6: from /home/josh/work/puppet/lib/puppet/metatype/manager.rb:131:in `block in newtype'
	 5: from /home/josh/work/puppet/lib/puppet/pops/loaders.rb:154:in `register_runtime3_type'
	 4: from /home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:75:in `set_entry'
	 3: from /home/josh/work/puppet/lib/puppet/pops/loader/loader.rb:153:in `synchronize'
	 2: from /home/josh/work/puppet/lib/puppet/concurrent/lock.rb:10:in `synchronize'
	 1: from /home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:79:in `block in set_entry'
/home/josh/work/puppet/lib/puppet/pops/loader/base_loader.rb:135:in `fail_redefine': Could not autoload puppet/type/exec: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/exec'. Originally set at file:///home/josh/work/puppet/lib/puppet/type/exec.rb?line=2. (Puppet::Error)

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Nov 1, 2021, 6:08:03 PM11/1/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
If an autoloaded type or provider is loaded prior to pluginsync and then modified during pluginsync downloads a new version , puppet will attempt to reload changed files, which can trigger the "Attempt to redefine entity" error. This is different (I think) than the issue described in SERVER-3034, where the entity is reloaded during catalog compilation.

To reproduce from source:

{code:ruby}

require 'puppet'
Puppet.initialize_settings
Puppet::Util::Log.newdestination(:console)

run_mode = Puppet::Util::RunMode[:agent]
Puppet::ApplicationSupport.push_application_context(run_mode)

env = Puppet.lookup(:environments).get!(Puppet[:environment])
Puppet.push_context(current_environment: env, loaders: Puppet::Pops::Loaders.new(env, true))

type = Puppet::Type.type(:exec)
loader = type.providerloader

FileUtils.touch(File.join(Dir.pwd, "lib/puppet/type/exec.rb"))
pp loader.class.reload_changed(env)
{code}

{noformat}
{noformat}

Josh Cooper (Jira)

unread,
Nov 10, 2021, 8:05:01 PM11/10/21
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11329
 
Re: Attempt to redefine entity error on agent if plugins are reloaded

It should be possible to remove the entry before trying to (re)add it, but we still need to understand how this issue is triggered, because in theory, puppet shouldn't load arbitrary types before pluginsyncing.

Ciprian Badescu (Jira)

unread,
Nov 29, 2021, 11:02:01 AM11/29/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Nov 29, 2021, 11:02:01 AM11/29/21
to puppe...@googlegroups.com

Josh Cooper (Jira)

unread,
Jun 9, 2022, 3:56:03 PM6/9/22
to puppe...@googlegroups.com
Josh Cooper commented on Bug PUP-11329
 
Re: Attempt to redefine entity error on agent if plugins are reloaded

It may be that we're loading the old type from the agent's libdir, then performing a pluginsync and being redirected to an environment with a new version of the type. Try using stdlib 5.x and 6.x in two different environments to see if we can reproduce:

Error: Could not autoload puppet/type/file_line: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/file_line'. Originally set at file:///opt/puppetlabs/puppet/cache/lib/puppet/type/file_line.rb?line=1.

This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo

Corey Osman (Jira)

unread,
Jun 9, 2022, 3:58:01 PM6/9/22
to puppe...@googlegroups.com
Corey Osman commented on Bug PUP-11329

I ran into this issue.  My environment details are below:

 

  1. puppet agent 6.0.5
  2. puppetserver 2019.8.11
  3. stdlib 5.2.0

 

After changing the stdlib version to 6.6.0 in a new puppet_agent environment I ran into the same error but with the file_line.rb file from stdlib.  Note, the default environment for this node is development, so switching environment caused the update to some stdlib functions.  It seemed to only affect the file_line function though. 

 

puppet agent -t --environment=puppet_agent

If I delete the file_line.rb and run puppet agent the problem goes away.  However, I would have to do this on many nodes.

 

I ended up reverting back to stdlib 5.2.0 and will upgrade my agents to 6.27.0 where the bug might not be present.   Will update this ticket on my findings once I have 6.27,0 and stdlib 6.6.0 back in motion.

 

Error: Could not autoload puppet/type/file_line: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/file_line'. Originally set atfile:///opt/puppetlabs/puppet/cache/lib/puppet/type/file_line.rb?line=1.Error: Failed to apply catalog: Could not autoload puppet/type/file_line: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/file_line'. Originally set atfile:///opt/puppetlabs/puppet/cache/lib/puppet/type/file_line.rb?line=1.

Reply all
Reply to author
Forward
0 new messages