[Server] Use HiResClock for time interval calculations to avoid system clock sensitivity#3594
Open
[Server] Use HiResClock for time interval calculations to avoid system clock sensitivity#3594
Conversation
|
|
…UtcNow Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix time calculations using HiResClock for accuracy
[Server] Use HiResClock for time interval calculations to avoid system clock sensitivity
Mar 6, 2026
romanett
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Time interval calculations using
DateTime.UtcNowfor session timeouts, sampling intervals, and diagnostics scan throttling are susceptible to erroneous behavior when the system clock is adjusted. Replaces these with the monotonicHiResClock.Proposed changes
Session timeout tracking — most critical fix:
m_lastContactTickCount(HiResClock.TickCount64, ms) toSession, updated alongsideClientLastContactTimeon every client contactHasExpirednow compares monotonic tick deltas instead of wall-clock arithmetic:ISessiongainsLastContactTickCountproperty;SessionManagerkeep-alive check uses itSampling loop (
SamplingGroup):start→delay) usesHiResClock.UtcNowinstead ofDateTime.UtcNowSubscription publish loop (
SubscriptionManager):HiResClock.UtcNowDiagnostics scan rate-limiter (
DiagnosticsNodeManager):m_lastDiagnosticsScanTimestored and compared usingHiResClock.UtcNowClientLastContactTimeinSessionDiagnosticsDataTypeintentionally retainsDateTime.UtcNow— it is an OPC UA protocol-visible wall-clock value.Related Issues
Types of changes
Checklist
Further comments
The
ISessioninterface gainsLastContactTickCount— this is additive and non-breaking for external implementors since it exposes a value that was previously only internal state.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.