Linux – Leap seconds and pthread_mutex_timedlock premature timeouts

Leap seconds and pthread_mutex_timedlock premature timeouts… here is a solution to the problem.

Leap seconds and pthread_mutex_timedlock premature timeouts

Just recently, my async server code that relies on pthread_mutex_timedlock seems to have timed out prematurely. At first I thought it was just my bug, but seeing that the linux kernel has some leap second issues, it seems that I am not the only problem: https://lkml.org/lkml/2012/7/1/11

What is the current fix for this? Reboot the server, or update the kernel? My server relies on the timedlock mechanism to wait for events from other threads, and because of this premature timeout, the CPU usage is always at 100% because it never stays on the timed lock.

I am currently running ubuntu server 10.04.4 with kernel version 2.6.39.1

Solution

Well, I came across http://forums.pentaho.com/showthread.php?98217-Java-leap-second-bug-how-to-fix-your-broken-servers&s=5836d11a51327406f965c66fddc9149d&p=286479#post286479

This works under sudo:

/etc/init.d/ntp stop; date; date `date +"%m%d%H%M%C%y.%S"`; date; /etc/init.d/ntp start

(Freenode’s #kernel says date -s "\date\" fixes it.)

This is also confirmed by the drop in CPU usage from about 100% to 0.5%. So I guess that’s it until the next leap second inserts.

Related Problems and Solutions