如何在不重新啟動的情況下解決閏秒睡眠問題

如何在不重新啟動的情況下解決閏秒睡眠問題

我發現在最新的閏秒插入(2016-12-31 23:59:60)之後,我們的 CentOS7 應用程式(工作線程在作業之間休眠 1 秒)開始立即喚醒休眠線程,而不是一秒鐘。一般來說,所有睡眠都會比預期醒來時間提早 1 秒醒來。

最簡單有效的解決方案是重新啟動盒子。但在我們的例子中這是不可取的。有沒有辦法在不重新啟動的情況下解決這個問題?

附言。作為參考,這裡有一個簡單的 C++ 程序,可以重現問題。

#include <boost/date_time.hpp>
#include <boost/thread.hpp>
#include <iostream>

using namespace std;


// this has to be run in a thread to be able to detect the issue
void check_thread()
{
    size_t expected_delay = 1000;
    cout << "Expected delay: " << expected_delay << " ms" << endl;
    boost::posix_time::ptime t1 = boost::posix_time::microsec_clock::universal_time();
    boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
    boost::posix_time::ptime t2 = boost::posix_time::microsec_clock::universal_time();
    size_t actual_delay = (t2 - t1).total_milliseconds();
    cout << "Actual delay: " << actual_delay << " ms" << endl;
    if (abs(expected_delay - actual_delay) > 900) {
        cout << "Too big delay difference: " << (expected_delay - actual_delay) << endl;
        cout << "Possible leap second issue" << endl;
    }
    else {
        cout << "No issues found" << endl;
    }
}

int main()
{
    boost::thread_group g;
    g.create_thread(check_thread);
    g.join_all();
    return 0;
}

建築:

g++ sleep_test.cpp -Wl,-Bstatic -lboost_thread -lboost_system -lboost_date_time -Wl,-Bdynamic -rdynamic -pthread

答案1

您的系統時間與ntpd或同步嗎ptp?如果沒有,請更新您的tzdata軟體包。

對於未通過 ntpd 或 ptp 同步的系統,需要包含 12 月 31 日閏秒的更新 tzdata 套件。更新後的 tzdata 軟體包作為 RHEA-2016-1982 的一部分發布,任何使用 RHEL 7 且未通過 ntpd 或 ptp 同步的系統應更新至 tzdata-2016g-2.el7 或更高版本,以接收此修復。

解決 Red Hat Enterprise Linux 中的閏秒問題

答案2

除了 Troy 所說的之外,在應用閏秒時尚未更新 tzdata 並且未運行 ntpd 的 RHEL7 系統上,需要一個額外的步驟 - 手動將時間向前設置 1 秒,然後將其恢復:

date -s "+1 sec"
date -s "-1 sec"

相關內容