Issue #13441 has been updated by Kelsey Hightower.

Status changed from Investigating to Accepted
Assignee deleted (Kelsey Hightower)
Affected Puppet version set to 2.7.14

So this is a real bug. I was able to reproduce this with the following manifest:

    # This should run for at least 10 seconds
    exec { 'timeout_test':
      command => '/bin/sleep 3',
      returns => 2,
      timeout => 2,
      tries   => 5,
    }

My command only gets run once:


    debug: /Stage[main]//Exec[timeout_test]/returns: Exec try 1/5
    debug: Exec[timeout_test](provider=posix): Executing '/bin/sleep 3'
    debug: Executing '/bin/sleep 3'
    err: /Stage[main]//Exec[timeout_test]/returns: change from notrun to 2 
failed: Command exceeded timeout at /Users/kelseyhightower/bug13441.pp:7
    debug: /Schedule[never]: Skipping device resources because running on a host
    debug: /Schedule[weekly]: Skipping device resources because running on a 
host
    debug: /Schedule[puppet]: Skipping device resources because running on a 
host
    debug: Finishing transaction 2253004880
    debug: Storing state
    debug: Stored state in 0.01 seconds
    notice: Finished catalog run in 2.04 seconds
    debug: Finishing transaction 2252422000
    debug: Received report to process from hightower-2.local
    debug: Processing report from hightower-2.local with processor 
Puppet::Reports::Store

This is in conflict with the documentation around the [exec 
resource](http://docs.puppetlabs.com/references/stable/type.html#exec):

> The number of times execution of the command should be tried. Defaults to 
> ‘1’. This many attempts will be made to execute the command until an 
> acceptable return code is returned. Note that the timeout paramater applies 
> to each try rather than to the complete set of tries.
----------------------------------------
Bug #13441: A command that times out will not re-execute if "tries" is set.
https://projects.puppetlabs.com/issues/13441#change-62058

Author: Lars Kellogg-Stedman
Status: Accepted
Priority: Normal
Assignee: 
Category: exec
Target version: 
Affected Puppet version: 2.7.14
Keywords: 
Branch: 


I was expecting something like this to retry execution if the command timed out:

    exec { '/path/to/mycommand':
      tries => 2,
      timeout => 10,
    }

Unfortunately, the exception generated by a timeout resumes control outside of 
the retry loop:

        begin
          tries.times do |try|
            # Only add debug messages for tries > 1 to reduce log spam.
            debug("Exec try #{try+1}/#{tries}") if tries > 1
            @output, @status = provider.run(self.resource[:command])
            break if self.should.include?(@status.exitstatus.to_s)
            if try_sleep > 0 and tries > 1
              debug("Sleeping for #{try_sleep} seconds between tries")
              sleep try_sleep
            end
          end
        rescue Timeout::Error
          self.fail "Command exceeded timeout" % value.inspect
        end

I'm not sure how to deal with commands that may need to be retried due to 
timeouts.  Would it be possible to move the retry loop outside of the try/catch?



-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to