cloudflare / cfrpki

Cloudflare's RPKI Toolbox
https://rpki.cloudflare.com
BSD 3-Clause "New" or "Revised" License
175 stars 44 forks source link

Fixed regression to 'File not ready yet' state #120

Open colinmcintosh opened 1 year ago

colinmcintosh commented 1 year ago

This PR fixes an issue that causes octorpki to return the 'File not ready yet' state after previously achieving a stable state.

There are two functions that lead me to believe reverting to the 'File not ready yet' state is not the intended behavior of octorpki. In both ServeROAs and ServeHealth the code checks for s.Stable and s.HasPreviousStable, seemingly to continue serving ROAs if the state was once stable but isn't currently. The only place s.HasPreviousStable is set is immediately after s.Stable is set on octorpki.go#L1254 so whenever s.Stable reverts to false after s.MainReduce() so will s.HasPreviousStable. Both s.Stable and s.HasPreviousStable being false will cause octorpki to revert to a state where no ROAs are served and instead a message is returned: 'File not ready yet'. s.Stable is also set after the validation interval expires but that will result in s.HasPreviousStable only being true for a single additional iteration, after which it may revert to false (based on the result of s.MainReduce()).

The fix adds check to only set s.HasPreviousStable when s.Stable is true.

While I was making this change I also noticed that s.HasPreviousStable isn't set after MaxIterations is reached which similarly would result in the ROA list switching back and forth between available and 'File not ready yet'. I updated that to also set s.HasPreviousStable.

Happy to make any adjustments to this PR as needed. Please let me know if I'm misunderstanding the intended use of s.HasPreviousStable at all. Thanks!