[c-nsp] leap sec adjust. may crash linux based platforms

Saku Ytti saku at ytti.fi
Thu Dec 22 07:00:49 EST 2016


On 21 December 2016 at 18:45, Lukas Tribus <luky-37 at hotmail.com> wrote:
> "Leap smearing" like Google does [3] may work around this.

I believe this is only realistic fix, until ITU finally removes leap
from UTC. If there was way to do leap at presentation layer, that
would also probably work, but machines cannot cope with non-monotonic
time.

Imagine code like this

INTERVAL = 42
loop do
  loop_start = Time.now
  do_fancy_stuff
  loop_duration = Time.now-loop_start
  if duration < 42
    sleep INTERVAL-duration
  end
end


intention of this code of course is that if loop takes less than 42s,
we sleep the delta. The problem of this code, and any other code which
tries to calculate passage of time comparing two timestamps, is that
it assumes wall time is monotonic, which it is not. During leap second
'loop_duration' might become large negative number, and sleep might
take centuries.

I'm sure there are lot and lot of broken code like this. But it'll
only bite you if it happens to run during the the leap second and
happens to run in under a second. So in most cases it's gamble where
you rarely lose. But I'll  be good money that JunOS, IOS etc are full
of code like that.

It may not even be very easy problem to fix. Most problems provide
platform dependant monotonic time, which is guaranteed only to
increase, which can be used here to measure passage of time, however
those times are not serialisable, you cannot send them to another
machine in network and have some meaning at the other machine too, so
they only work runtime on a single machine. JunOS/IOS etc having
control-plane redundancy appear to need serialisable monotonic time,
there is none.
So only thing you can do, is leap smear or gamble.


-- 
  ++ytti


More information about the cisco-nsp mailing list