Fix SourceTimestamp for variables without explicit timestamps in BaseVariableState#3451
Conversation
|
|
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
set loglevel in session publish when no subscriptions ignore more keepalive errors in Client Fixture
|
@copilot please investigate why for arrays the timestamp is still set to server startup time instead of current time. even with the current fix. |
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Fixed in commit df0e8df. The issue was in BaseVariableState.ReadValueAttribute which only set the timestamp once when it was DateTime.MinValue, then never updated it on subsequent reads. Changed to always update timestamp on every read. Both scalar and array variables now correctly update timestamps (verified with new array test). |
|
@copilot please update the PR description to reflect the actual changes done in the code |
The PR description should be updated to reflect the actual fix implemented in commit 810d656. The current description states that Actual Fix: if (m_timestamp == DateTime.MinValue)
{
sourceTimestamp = DateTime.UtcNow;
}
else
{
sourceTimestamp = m_timestamp;
}Instead of modifying internal state on every read, the fix returns |
Proposed changes
Variables without explicit timestamps (such as static variables in ReferenceNodeManager) were returning stale SourceTimestamp values instead of current time on reads. This was caused by BaseVariableState.ReadValueAttribute setting the internal
m_timestamponce when it wasDateTime.MinValue, then using that stale value for all subsequent reads. This caused CTT test failures in Attribute Services / Attribute Read / Test Case 006.js.Fix: Modified BaseVariableState.ReadValueAttribute to return
DateTime.UtcNowforsourceTimestampwhenm_timestamp == DateTime.MinValue, without modifying the internal state.Root Cause
The issue was in
Stack/Opc.Ua.Types/State/BaseVariableState.cswhere the timestamp was set once and then reused:After the first read,
m_timestampwould have a value set to that first read time, causing all subsequent reads to return the same stale timestamp.Changes
ReadValueAttributeto return current time for sourceTimestamp without modifying internal stateReferenceNodeManagerVariablesUpdateTimestampOnReadAsync- verifies scalar variablesReferenceNodeManagerArrayVariablesUpdateTimestampOnReadAsync- verifies array variablesSolution
This approach:
DateTime.UtcNow) for variables without explicit timestamps (static variables)Types of changes
Checklist
Further comments
Test output shows timestamps correctly returning current time for both scalars and arrays on each read.
All existing server tests pass (169 passed, 5 skipped).
The fix is implemented at the BaseVariableState level, ensuring all variables throughout the system benefit from proper timestamp handling. Variables with explicit timestamp management (like dynamic variables updated via DoSimulation) continue to use their managed timestamps, while variables without explicit timestamps (like static variables in ReferenceNodeManager) now return current time on each read instead of a stale timestamp from the first read.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.