Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roundtripping server-time on non UTC breaks #1779

Open
kylef opened this issue Feb 21, 2021 · 2 comments
Open

Roundtripping server-time on non UTC breaks #1779

kylef opened this issue Feb 21, 2021 · 2 comments

Comments

@kylef
Copy link
Member

kylef commented Feb 21, 2021

If the system's timezone is not configured to UTC, then roundtripping server-time does not behave correctly. This can cause issues with playback replay when both the server, and the client are using server-time and the system TZ is set to something that isn't UTC.

Internally, the following should produce same result as the input regardless of TZ setting.

FormatServerTime(ParseServerTime("2011-10-19T16:40:51.620Z"))

Given the following patch to demonstrate:

diff --git a/test/UtilsTest.cpp b/test/UtilsTest.cpp
index 44514d98..e2f37c29 100644
--- a/test/UtilsTest.cpp
+++ b/test/UtilsTest.cpp
@@ -86,15 +86,16 @@ TEST(IRC32, SetMessageTags) {
 }
 
 TEST(UtilsTest, ServerTime) {
-    char* oldTZ = getenv("TZ");
-    if (oldTZ) oldTZ = strdup(oldTZ);
-    setenv("TZ", "UTC", 1);
-    tzset();
 
     timeval tv1 = CUtils::ParseServerTime("2011-10-19T16:40:51.620Z");
     CString str1 = CUtils::FormatServerTime(tv1);
     EXPECT_EQ(str1, "2011-10-19T16:40:51.620Z");
 
+    char* oldTZ = getenv("TZ");
+    if (oldTZ) oldTZ = strdup(oldTZ);
+    setenv("TZ", "UTC", 1);
+    tzset();
+
     timeval now = CUtils::GetTime();
 
     // Strip microseconds, server time is ms only

and then run:

$ env TZ=Europe/Prague make unittest

[ RUN      ] UtilsTest.ServerTime
../test/UtilsTest.cpp:92: Failure
Expected equality of these values:
  str1
    Which is: "2011-10-19T15:40:51.620Z"
  "2011-10-19T16:40:51.620Z"
    Which is: 0x477667c0174

The test case looks like it was implemented incorrectly, hiding this problem. Z in ISO 8601 should be UTC on both sides.

@szlend
Copy link

szlend commented Feb 21, 2021

I've experienced this issue myself, causing gaps in the playback log. I worked around the issue by setting Environment=TZ=Etc/UTC in the ZNC systemd service. It only happens on servers with the server-time extension (e.g. oragono) and only for received messages. Messages sent from ZNC are unaffected. With the playback module you can see this issue by running /msg *playback list. The last message timestamp will be offset by your timezone.

@AndroidKitKat
Copy link

May or may not be related to this bug, but setting Etc/UTC as the Timezone and applying @kylef's patch #1780, I was able to solve this problem as well.

I did run into a slight issue with clientbuffer, but I resolved it by deleting and remaking clients. Not elegant but it worked.

kylef added a commit to kylef/znc that referenced this issue Jun 1, 2021
kylef added a commit to kylef/znc that referenced this issue Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants