Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chef-Solo loads configurations twice #6375

Open
gmeneze opened this issue Sep 1, 2017 · 1 comment · May be fixed by #8872

Comments

@gmeneze
Copy link

commented Sep 1, 2017

Description

chef-solo run loads the configuration file (solo.rb) twice when it's run. This causes duplication of handlers, resulting in the same handler being run twice.

Chef Version

We were able to replicate this for versions 12.14.89+

Platform Version

Red Hat Enterprise Linux Server release 6.8 (Santiago)

Replication Case

  1. Create a minimal solo.rb with an event handler : -
Chef.event_handler do
  on :converge_start do
    puts "Ohai! I have started a converge."
  end
end
  1. Run chef solo : -
sudo chef-solo -c ./solo.rb

Solo Output

$ sudo chef-solo -c ./solo.rb
[2017-09-01T20:10:07+00:00] WARN: No cookbooks directory found at or above current directory.  Assuming /var/chef.
[2017-09-01T20:10:07+00:00] WARN: No cookbooks directory found at or above current directory.  Assuming /var/chef.
Starting Chef Client, version 13.2.20
resolving cookbooks for run list: []
Synchronizing Cookbooks:
Installing Cookbook Gems:
Compiling Cookbooks...
Converging 0 resources
Ohai! I have started a converge.
Ohai! I have started a converge.

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 04 seconds
Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 04 seconds

The converge_start event handler is run twice, resulting in the statement "Ohai! I have started a converge" being printed twice.

My Analysis

When the chef-solo executable is run, it first loads the configurations in its run method, here : -
https://github.com/chef/chef/blob/master/lib/chef/application/solo.rb#L222

If the legacy mode flag is not passed to the chef-solo run, then this block of code is executed later on in the run method : -
https://github.com/chef/chef/blob/master/lib/chef/application/solo.rb#L225

This calls the run method of the application class, which calls reconfiguration method again, so the configuration file is loaded for the second time here : -
https://github.com/chef/chef/blob/master/lib/chef/application.rb#L57

This is fine for configurations like checksum_path, cookbook_path etc. as they are overwritten with the same value, but for chef-handlers (start_handlers, report_handlers, exception_handlers, event_handler), which are stored as arrays, it results in two similar objects getting inserted, which causes this problem.

@lamont-granquist

This comment has been minimized.

Copy link
Contributor

commented Sep 11, 2017

confirmed that the somewhat convoluted code where Chef::Application::Solo#run calls Chef::Application::Client#run is what is responsible.

the initial reconfigure call is necessary to load Chef::Config though and can't be moved to later, and then Client#run is necessary for client-like behavior, so it wasn't clear to me how to disentangle the concerns cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.