Forum: CFEngine Help
Subject: Re: copy_from: would like priority list of sources, then silent fail
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,25584,25793#msg-25793

To clarify (or confirm?), this works because the promise key is just the 
filename, and the first copy_from which works sets the promise as having been 
kept, so it would not be verified again until the minimum interval had passed?  
So, subsequent copy attempts would be skipped, due to the promise having 
already been verified?

If so, it seems like there's a race condition here.  Say you have cf-agent 
executing on a 5 minute interval.  And you have a five minute elapsed time 
interval on promises.  The first time this runs, file #1 copies succesfully.  
The second time cf-agent runs, maybe a few of the promises earlier in the 
policy run slightly quicker than usual (maybe cf-promises doesn't have to run 
because the inputs are unchanged), so five minutes hasn't elapsed yet when the 
first element in the copy_from slist is brought up as a candidate for 
verification.  But by the time you get to the third one, the five minutes has 
elapsed and the promise is again up for validation.  The third copy works, 
leaving your file in an unintended state.  Going forward, as long as all of 
your other promises take exactly the same time to evaluate, maybe the five 
minute timer and execution time may remain skewed just right so that the 
promise isn't up for reevaluation on the file1 and file2 checks, but comes up 
just i
 n time for file3 to be verified.  Your system stays in the wrong state until 
something happens to bump the phasing between the promise database and the 
cf-execd timer.

While somewhat obscure, it seems like this would be an actual possibility based 
on the presumption made earlier on, right?

I'm partial to defining a set of classes like "file1 exists", "file2 
exists&!file1 exists", "file3 exists & !file2 exists" and setting a variable 
"source" based on those, then grabbing $(source) only if $(source) is defined.  
It's quite as easy to extend, though. Hopefully someone can explain that my 
earlier assumption is wrong and that there is no race condition, 'cause Diego's 
solution is way prettier. :)

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to