Skip to content

fix(config): use actual file modification time in UpdateLastFileModTime#1668

Open
RaminGe wants to merge 5 commits into
TwiN:masterfrom
RaminGe:fix/issue-1657-config-watcher-clock-skew
Open

fix(config): use actual file modification time in UpdateLastFileModTime#1668
RaminGe wants to merge 5 commits into
TwiN:masterfrom
RaminGe:fix/issue-1657-config-watcher-clock-skew

Conversation

@RaminGe
Copy link
Copy Markdown

@RaminGe RaminGe commented May 14, 2026

Summary

Fixes #1657

Previously, UpdateLastFileModTime() set the last file modification time to time.Now(). In containerized environments with volume mounts (e.g. Kubernetes, Google Cloud Run), the mounted file's timestamp can be in the future relative to the container's internal clock. This caused the configuration watcher to continuously evaluate that the file had been modified (because config.lastFileModTime < fileInfo.ModTime()), triggering infinite restart loops and effectively disabling the alerting engine.

This PR updates UpdateLastFileModTime() to read the actual ModTime of the config file using os.Stat (and if it is a directory, using the newest ModTime inside that directory). It falls back to time.Now() only if the true modification time cannot be determined.

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable. -> Tested locally
  • Updated documentation in README.md, if applicable. -> Not applicable

Fixes TwiN#1657

Previously, UpdateLastFileModTime() set the last file modification time to time.Now(). In containerized environments with volume mounts (e.g. Kubernetes, Google Cloud Run), the mounted file's timestamp can be in the future relative to the container's internal clock. This caused the configuration watcher to continuously evaluate that the file had been modified (because config.lastFileModTime < fileInfo.ModTime()), triggering infinite restart loops and effectively disabling the alerting engine.

This commit updates UpdateLastFileModTime() to read the actual ModTime of the config file using os.Stat (and if it is a directory, using the newest ModTime inside that directory). It falls back to time.Now() only if the true modification time cannot be determined.
@github-actions github-actions Bot added the bug Something isn't working label May 14, 2026
@mgenoni
Copy link
Copy Markdown

mgenoni commented May 14, 2026

@RaminGe 🐎🔥

Copy link
Copy Markdown
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thank you for the contribution!

Comment thread config/config.go Outdated
Comment thread config/config.go Outdated
@TwiN
Copy link
Copy Markdown
Owner

TwiN commented May 19, 2026

@RaminGe is there any chance you could add a test for your change?

@RaminGe
Copy link
Copy Markdown
Author

RaminGe commented May 19, 2026

@RaminGe is there any chance you could add a test for your change?

@TwiN done!

@RaminGe RaminGe force-pushed the fix/issue-1657-config-watcher-clock-skew branch from 9694312 to e02d076 Compare May 20, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constant restart loop triggered by listenToConfigurationFileChanges preventing Slack alerts

3 participants