{"record":{"id":"d9086eca068506f0","repo":"puppetlabs/puppet","slug":"failed-to-fetch-services","errorCode":null,"errorMessage":"Failed to fetch services","messagePattern":"Failed to fetch services","errorType":"exception","errorClass":"Puppet::Util::Windows::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/service.rb","lineNumber":258,"sourceCode":"              )\n              size_required = bytes_pointer.read_dword\n              FFI::MemoryPointer.new(size_required) do |buffer_ptr|\n                resume_ptr.write_dword(0)\n                svcs_ret_ptr.write_dword(0)\n                success = EnumServicesStatusExW(\n                  scm,\n                  :SC_ENUM_PROCESS_INFO,\n                  ALL_SERVICE_TYPES,\n                  SERVICE_STATE_ALL,\n                  buffer_ptr,\n                  buffer_ptr.size,\n                  bytes_pointer,\n                  svcs_ret_ptr,\n                  resume_ptr,\n                  FFI::Pointer::NULL\n                )\n                if success == FFI::WIN32_FALSE\n                  raise Puppet::Util::Windows::Error, _(\"Failed to fetch services\")\n                end\n\n                # Now that the buffer is populated with services\n                # we pull the data from memory using pointer arithmetic:\n                # the number of services returned by the function is\n                # available to be read from svcs_ret_ptr, and we iterate\n                # that many times moving the cursor pointer the length of\n                # ENUM_SERVICE_STATUS_PROCESSW.size. This should iterate\n                # over the buffer and extract each struct.\n                services_returned = svcs_ret_ptr.read_dword\n                cursor_ptr = FFI::Pointer.new(ENUM_SERVICE_STATUS_PROCESSW, buffer_ptr)\n                0.upto(services_returned - 1) do |index|\n                  service = ENUM_SERVICE_STATUS_PROCESSW.new(cursor_ptr[index])\n                  services[service[:lpServiceName].read_arbitrary_wide_string_up_to(SERVICENAME_MAX)] = {\n                    :display_name => service[:lpDisplayName].read_arbitrary_wide_string_up_to(SERVICENAME_MAX),\n                    :service_status_process => service[:ServiceStatusProcess]\n                  }\n                end","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/service.rb#L240-L276","documentation":"Raised by services (the enumerator) when EnumServicesStatusExW returns FALSE while paging through all services of all states. The call runs with a 30KB-ish buffer and retries with the required size, so residual failures are usually environmental: SCM access denied, the service database locked, or the RPC endpoint unavailable. The appended Win32 text names the cause.","triggerScenarios":"Calling Puppet::Util::Windows::Service.services on a machine where the SCM denies SC_MANAGER_ENUMERATE_SERVICE, during concurrent service installation/uninstallation (database locked), or when the RPC server (RpcSs) is not healthy.","commonSituations":"Service discovery at the start of a Puppet run colliding with MSI installers or updates installing services; hardened boxes restricting SCM enumeration; boot-time runs before the SCM is fully ready.","solutions":["Read e.code: 5 = access denied, 1071 = service database locked, 1717 = RPC server unavailable","Retry the enumeration after a short wait when the box is mid-update","Run elevated so the SCM handle carries enumeration rights","If RpcSs is failing, check its health (sc query rpcss) before retrying"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"def list_services(tries: 3)\n  Puppet::Util::Windows::Service.services\nrescue Puppet::Util::Windows::Error => e\n  retry if (tries -= 1) > 0 && [5, 1071, 1717, 1722].include?(e.code) # denied/locked/RPC\n  raise\nend","preventionTips":["Retry enumeration with backoff; SCM contention during installs is transient","Run elevated on hardened boxes that restrict enumeration","Avoid kicking off service management while Windows Update is installing services"],"tags":["windows","service","win32","enumeration","scm","rpc"],"backgroundTag":"windows-service-enumeration-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}