puppetlabs/puppet · error · Puppet::Util::Windows::Error

Service query failed

Error message

Service query failed

What it means

Raised by the private query_status helper when QueryServiceStatusEx returns FALSE after a first sizing call succeeded. The handle must have been opened with SERVICE_QUERY_STATUS. Typical Win32 causes: the handle is stale or was closed, access is denied, or the service is marked for deletion so the SCM refuses further queries. It propagates out of service_state, start/stop transitions, and exists? checks.

Source

Thrown at lib/puppet/util/windows/service.rb:442

          QueryServiceStatusEx(
            service,
            :SC_STATUS_PROCESS_INFO,
            FFI::Pointer::NULL,
            0,
            bytes_pointer
          )
          size_required = bytes_pointer.read_dword
          FFI::MemoryPointer.new(size_required) do |ssp_ptr|
            status = SERVICE_STATUS_PROCESS.new(ssp_ptr)
            success = QueryServiceStatusEx(
              service,
              :SC_STATUS_PROCESS_INFO,
              ssp_ptr,
              size_required,
              bytes_pointer
            )
            if success == FFI::WIN32_FALSE
              raise Puppet::Util::Windows::Error, _("Service query failed")
            end

            yield status
          end
        end
      end
      private :query_status

      # @api private
      # perform QueryServiceConfigW on a windows service and return the
      # result
      #
      # @param [:handle] service handle of the service to query
      # @return [QUERY_SERVICE_CONFIGW struct] the result of the query
      def query_config(service, &block)
        config = nil
        size_required = nil
        # Fetch the bytes of memory required to be allocated

View on GitHub (pinned to e227c27540)

Solutions

  1. Check e.code: 1072 = marked for delete, 5 = access denied, 1060 = service gone
  2. Re-open the service and retry once when the error follows an uninstall/reinstall
  3. Ensure the code requests SERVICE_QUERY_STATUS (Puppet's helpers already do) and the token allows it
  4. If 1072 keeps firing, reboot or clear the deletion by closing other handles (sc stop on lingering processes)
Defensive patterns

Strategy: try-catch

Try / catch

begin
  Puppet::Util::Windows::Service.service_state(name)
rescue Puppet::Util::Windows::Error => e
  if e.code == 1072 # ERROR_SERVICE_MARKED_FOR_DELETE
    raise Puppet::Error, "#{name} is marked for deletion; close handles or reboot"
  end
  raise
end

Prevention

When it happens

Trigger: Querying status on a service deleted while a handle was open (ERROR_SERVICE_MARKED_FOR_DELETE, 1072); a handle opened without SERVICE_QUERY_STATUS; SCM/RPC failures mid-query; races where the service is uninstalled between open_service and the query.

Common situations: Uninstall/reinstall churn during the run (MSI removing the service under Puppet); monitoring code holding handles across service deletion; least-privileged tokens lacking query rights.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/e4789c61c1e20c5f. Report an issue: GitHub.