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

tests fail around DST #569

Open
Tracked by #576
skazi0 opened this issue Dec 27, 2023 · 3 comments
Open
Tracked by #576

tests fail around DST #569

skazi0 opened this issue Dec 27, 2023 · 3 comments

Comments

@skazi0
Copy link

skazi0 commented Dec 27, 2023

When logrotate testsuite is started around midnight, shortly after DST switch day some tests are failing because test environment is not generated correctly. We saw this problem with test #54 and #56.
Example reproducer based on test-0054.sh:

#export TZ=UTC
mkdir -p test
cd test
rm -f test.log*
sudo date -s '2023-11-28 23:16:54'
DATE=""
for i in $(seq 1 60)
do
    if date -v -1d > /dev/null 2>&1; then
        DATE=$(date -v-${i}d "+%Y-%m-%d")
    else
        DATE=$(date "+%Y-%m-%d" --date "$i day ago")
    fi
    echo "x" > test.log-$DATE
    echo test.log-$DATE
done
touch test.log
ls -1 | wc -l
echo $DATE
cd ..
rm -f state
logrotate -s state test-config.56 --force
test -e test/test.log-$DATE && echo "ERROR: file should not exist!" || echo OK

When this is ran in a timezone with DST it prints:

Tue Nov 28 23:16:54 PST 2023
test.log-2023-11-27
test.log-2023-11-26
test.log-2023-11-25
test.log-2023-11-24
test.log-2023-11-23
test.log-2023-11-22
test.log-2023-11-21
test.log-2023-11-20
test.log-2023-11-19
test.log-2023-11-18
test.log-2023-11-17
test.log-2023-11-16
test.log-2023-11-15
test.log-2023-11-14
test.log-2023-11-13
test.log-2023-11-12
test.log-2023-11-11
test.log-2023-11-10
test.log-2023-11-09
test.log-2023-11-08
test.log-2023-11-07
test.log-2023-11-06
test.log-2023-11-05
test.log-2023-11-05
test.log-2023-11-04
test.log-2023-11-03
test.log-2023-11-02
test.log-2023-11-01
test.log-2023-10-31
test.log-2023-10-30
test.log-2023-10-29
test.log-2023-10-28
test.log-2023-10-27
test.log-2023-10-26
test.log-2023-10-25
test.log-2023-10-24
test.log-2023-10-23
test.log-2023-10-22
test.log-2023-10-21
test.log-2023-10-20
test.log-2023-10-19
test.log-2023-10-18
test.log-2023-10-17
test.log-2023-10-16
test.log-2023-10-15
test.log-2023-10-14
test.log-2023-10-13
test.log-2023-10-12
test.log-2023-10-11
test.log-2023-10-10
test.log-2023-10-09
test.log-2023-10-08
test.log-2023-10-07
test.log-2023-10-06
test.log-2023-10-05
test.log-2023-10-04
test.log-2023-10-03
test.log-2023-10-02
test.log-2023-10-01
test.log-2023-09-30
60
2023-09-30
ERROR: file should not exist!

Note that it prints test.log-2023-11-05 twice and ands on 2023-09-30 not 2023-09-29 as expected.
When first line with TZ=UTC (there is not DST in UTC) enabled, the result is correct.
I didn't do any deeper analysis of how should logrotate itself behave around DST but the test is clearly not behaving as expected.

@cgzones
Copy link
Member

cgzones commented Dec 28, 2023

Can you re-test with the recent commit b2271cf?

@skazi0
Copy link
Author

skazi0 commented Dec 29, 2023

Thanks @cgzones for pointing me to this change.
It makes the test sequence consistent but the test still fails because the time range is shifted to UTC while logrotate still runs in local timezone.
With time set to Tue Nov 28 23:16:54 PST 2023 it tries to rotate test.log to test.log-2023-11-28 which already exists as part of the test sequence (error: destination (...)/test/test.log-2023-11-28 already exists, skipping rotation).
The test passes when I add TZ=UTC in front of logrotate call but I think a proper fix should be made inside logrotate itself because in real scenarios the TZ could be different.

cgzones added a commit to cgzones/logrotate that referenced this issue Jan 5, 2024
Using a local timezone with DST might result in a date returned twice,
see logrotate#569.
@cgzones
Copy link
Member

cgzones commented Jan 5, 2024

The duplicate test log with the same date is resolved with #572.

Changing the timezone handling inside logrotate (from local to UTC (i.e. localtime_r(3) to gmtime_r(3)) might need a deeper review. There seems to be hardly any bug reports around this topic.
As workaround one could run logrotate with an environment variable of TZ=UTC to force a specific timezone.

@cgzones cgzones mentioned this issue Jan 5, 2024
8 tasks
cgzones added a commit that referenced this issue Mar 15, 2024
Using a local timezone with DST might result in a date returned twice,
see #569.
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

2 participants