Hacker News new | past | comments | ask | show | jobs | submit login

Very interesting detail about linux and setting the time back to a value such that the boot time is before the epoch, with monotonic clocks.

Shamelessly I'll here remind people to never use gettimeofday() to measure time. E.g. setting the time backwards used to cause any currently running "ping" command to hang. (they fixed it about 10 years after I sent them a patch)

More fun examples of bugs like that at https://blog.habets.se/2010/09/gettimeofday-should-never-be-...




I have made that same mistake a few times myself.

It comes from a natural inclination of I want something to expire some period from now.

The natural way is to say what time is it now. Figure out what time you want to expire with a date add. Then busy wait until that time expires using some form of gettime. The very big assumption you make is that the gettime methods always move forward. They dont.

This bug is easy to make thinking you are treating a wait item as a calendar event. Its not. You need to find something to busy wait on, that always counts up. Do not use the system clock. Also pick something that counts at a known fixed rate. Not all counters are equal. Some can skew by large margins after an hour and triggering when you do not expect. Which makes people want to reach for the system clock again. If you somehow decide 'i will use the clock' be prepared for some pain of the dozens of different ways that fails.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: