znc / znc

Official repository for the ZNC IRC bouncer
https://znc.in/
Apache License 2.0
2k stars 377 forks source link

listsockets printing 1970's dates. #1910

Open RealKindOne opened 3 months ago

RealKindOne commented 3 months ago

Juest reported the bug in#znc.

I did a git bisect and finally found the offending commit after a few hours:

42fdf9b49f374849d4177f6e185e70a6541f7d31

[03:00:59] <Test1> list
[03:00:59] <*listsockets> +--------------+-------------------------+----------+-----+----------------+-----------------+-------+-------+
[03:00:59] <*listsockets> | Name         | Created                 | State    | SSL | Local          | Remote          | In    | Out   |
[03:00:59] <*listsockets> +--------------+-------------------------+----------+-----+----------------+-----------------+-------+-------+
[03:00:59] <*listsockets> | _LISTENER    | 1970-01-22 00:15:44.884 | Listener | No  | :: 9999        |                 | 0 B   | 0 B   |
[03:00:59] <*listsockets> | USR::KindOne | 1970-01-22 00:15:46.303 | Inbound  | No  | 127.0.0.1 9999 | 127.0.0.1 54337 | 203 B | 1 KiB |
[03:00:59] <*listsockets> +--------------+-------------------------+----------+-----+----------------+-----------------+-------+-------+
psychon commented 3 months ago

Previously, millitime() used gettimeofday to get the current time. With the above update, it is switched to std::chrono::steady_clock::now(). That one uses the monotonic clock and doesn't produce sensible values when interpreted as a wall clock timestamp.

RealKindOne commented 3 months ago

Here is a test for when it gets fixed.

$ test/integration/inttest --gtest_filter=ZNCTest.ListsocketsModule
// https://github.com/znc/znc/issues/1910
TEST_F(ZNCTest, ListsocketsModule) {
    auto znc = Run();
    auto ircd = ConnectIRCd();
    auto client = LoginClient();
    client.Write("znc loadmod listsockets");
    client.ReadUntil("Loaded module");
    client.Write("PRIVMSG *listsockets :list");
    // Look for year 20xx, not 1970.
    client.ReadUntil("| _LISTENER       | 20");
}
DarthGandalf commented 3 months ago

This test will break in year 2100 though :(

RealKindOne commented 3 months ago

Add a TODO and deal with it later.

// TODO: Fix before Year 2100 - https://xkcd.com/1782/
// https://github.com/znc/znc/issues/1910
TEST_F(ZNCTest, ListsocketsModule) {
...