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

Windows Service Provider's current_delayed_start enumerates all services #8195

Open
jhenkens opened this Issue Jan 31, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@jhenkens
Copy link

jhenkens commented Jan 31, 2019

Description

When using the windows_service provider, in the load_current_resource resource, we call current_delayed_start which enumerates over every Windows Service on the platform via the stack trace

C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `upto'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `services'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:285:in `current_delayed_start'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:78:in `load_current_resource'

It not only does it once, but it does it twice, due to gating the assignment with the method call, rather than a local variable, issuing an excessive number of syscalls. Additionally, if loading the service config for any unrelated service fails, then the entire resource fails, which is the problem I encountered that brought me to this point.

The solution could instead be to extend https://github.com/chef/win32-service/blob/master/lib/win32/service.rb to be able to get the current_delayed_start directly, via the rescue'd block here https://github.com/chef/win32-service/blob/master/lib/win32/service.rb#L1090, and call that method directly, rather than enumerating over every service.

Chef Version

chef_version=14.7.17

Platform Version

platform=windows
platform_version=10.0.17134

Replication Case

I'm unsure as to how to create a replication case, but the service that is failing is pvhdparser. A similar bug was reported in puppet, but it is further down the method call. A latter puppet issue is also filed at the same line in the issue call, and is marked closed, but I don't see any actual changes

Stacktrace

SystemCallError: windows_service[_TTD-ServiceName] (ttd_dev_env::build line 62) had an error: SystemCallError: Element not found. - QueryServiceConfig: Element not found.
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ffi-win32-extensions-1.0.3/lib/ffi/win32/extensions.rb:64:in `raise_windows_error'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1346:in `get_config_info'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1063:in `block in services'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `upto'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `services'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:285:in `current_delayed_start'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:78:in `load_current_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider.rb:165:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource.rb:578:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:70:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `block (2 levels) in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `each'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `block in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:97:in `converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:720:in `block in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:715:in `catch'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:715:in `converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:754:in `converge_and_save'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:286:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:279:in `block in run_chef_client'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:261:in `run_chef_client'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application/client.rb:440:in `run_application'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:66:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application/solo.rb:224:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/bin/chef-solo:24:in `<top (required)>'
C:/opscode/chefdk/bin/chef-solo:312:in `load'
C:/opscode/chefdk/bin/chef-solo:312:in `<main>'
>>>> Caused by SystemCallError: Element not found. - QueryServiceConfig: Element not found.
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/ffi-win32-extensions-1.0.3/lib/ffi/win32/extensions.rb:64:in `raise_windows_error'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1346:in `get_config_info'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1063:in `block in services'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `upto'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/win32-service-1.0.1/lib/win32/service.rb:1035:in `services'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:285:in `current_delayed_start'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider/service/windows.rb:78:in `load_current_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/provider.rb:165:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource.rb:578:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:70:in `run_action'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `block (2 levels) in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `each'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:98:in `block in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/runner.rb:97:in `converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:720:in `block in converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:715:in `catch'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:715:in `converge'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:754:in `converge_and_save'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/client.rb:286:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:303:in `run_with_graceful_exit_option'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:279:in `block in run_chef_client'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:261:in `run_chef_client'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application/client.rb:440:in `run_application'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application.rb:66:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/lib/chef/application/solo.rb:224:in `run'
C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17-universal-mingw32/bin/chef-solo:24:in `<top (required)>'
C:/opscode/chefdk/bin/chef-solo:312:in `load'
C:/opscode/chefdk/bin/chef-solo:312:in `<main>'

If the above thoughts look valid, I am willing to make appropriate changes myself in both repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment