Skip to content

Conversation

romanett
Copy link
Contributor

Proposed changes

This pull request improvements to session management server. The main changes include refactoring session-related interfaces and implementations to support asynchronous operations, replacing lock-based synchronization with SemaphoreSlim for better scalability. These changes enhance the server's ability to handle concurrent requests efficiently and pave the way for modern async workflows.

Session Management Refactoring (Async Support)

  • Refactored ISessionManager and its implementation to use async methods for session startup, creation, activation, and closing, replacing synchronous methods with ValueTask-based async counterparts. Introduced a new CreateSessionResult class to encapsulate session creation results.

  • Updated IServerInternal and ServerInternalData to support async session closing via CloseSessionAsync, propagating async session management throughout the server stack.

Concurrency Improvements

  • Replaced traditional locking (lock/Lock) with SemaphoreSlim for thread-safe access to shared resources in session management and global discovery server code, improving scalability and responsiveness.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which adds functionality)
  • Test enhancement (non-breaking change to increase test coverage)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected, requires version increase of Nuget packages)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc.
  • I have signed the CLA.
  • I ran tests locally with my changes, all passed.
  • I fixed all failing tests in the CI pipelines.
  • I fixed all introduced issues with CodeQL and LGTM.
  • I have added tests that prove my fix is effective or that my feature works and increased code coverage.
  • I have added necessary documentation (if appropriate).
  • Any dependent changes have been merged and published in downstream modules.

Further comments

romanett and others added 30 commits September 14, 2025 16:48
…AsyncNodeManager

Refactor MasterNodeManager to allow access to IAsyncNodeManager from NodeManagers & NamespaceManagers Properties
@romanett romanett changed the title Feat/more async [Server] Async ActivateSession / CreateSession Sep 24, 2025
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 9.84043% with 339 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.30%. Comparing base (8053989) to head (99c7050).

Files with missing lines Patch % Lines
Libraries/Opc.Ua.Server/Server/StandardServer.cs 9.80% 276 Missing ⚠️
Libraries/Opc.Ua.Server/Session/SessionManager.cs 0.00% 25 Missing ⚠️
Stack/Opc.Ua.Core/Stack/Server/ServerBase.cs 17.24% 24 Missing ⚠️
...a.Gds.Server.Common/GlobalDiscoverySampleServer.cs 0.00% 6 Missing ⚠️
...braries/Opc.Ua.Server/Server/ServerInternalData.cs 0.00% 5 Missing ⚠️
...aries/Opc.Ua.Server/Server/ReverseConnectServer.cs 33.33% 2 Missing ⚠️
...raries/Opc.Ua.Configuration/ApplicationInstance.cs 50.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (8053989) and HEAD (99c7050). Click for more details.

HEAD has 7 uploads less than BASE
Flag BASE (8053989) HEAD (99c7050)
25 18
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3225       +/-   ##
===========================================
- Coverage   57.55%   26.30%   -31.26%     
===========================================
  Files         356      340       -16     
  Lines       78784    76927     -1857     
  Branches    13870    13528      -342     
===========================================
- Hits        45347    20235    -25112     
- Misses      29193    54477    +25284     
+ Partials     4244     2215     -2029     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@romanett romanett changed the title [Server] Async ActivateSession / CreateSession [Server] Async ActivateSession / CreateSession / FindServersAsync / GetEndpointsAsync / CloseSessionAsync Sep 24, 2025
@romanett romanett changed the title [Server] Async ActivateSession / CreateSession / FindServersAsync / GetEndpointsAsync / CloseSessionAsync [Server] ActivateSessionAsync / CreateSessionAsync / FindServersAsync / GetEndpointsAsync / CloseSessionAsync Sep 24, 2025
@romanett romanett requested a review from Copilot September 24, 2025 06:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors session management interfaces and implementations to support asynchronous operations, replacing synchronous methods with ValueTask-based async counterparts and improving concurrency through SemaphoreSlim instead of traditional locking.

  • Refactored session-related interfaces (ISessionManager, IServerInternal) to use async methods for session operations
  • Replaced lock statements with SemaphoreSlim for better scalability in concurrent scenarios
  • Enabled async support for FindServers, GetEndpoints, CreateSession, ActivateSession, and CloseSession operations

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Stack/Opc.Ua.Core/Stack/Server/ServerBase.cs Converted certificate update handler to async and improved exception handling
Stack/Opc.Ua.Core/Opc.Ua.Core.csproj Removed exclusions for async versions of FindServers, GetEndpoints, CreateSession, ActivateSession, and CloseSession
Libraries/Opc.Ua.Server/Session/SessionManager.cs Refactored session manager to use async methods and SemaphoreSlim for synchronization
Libraries/Opc.Ua.Server/Session/ISessionManager.cs Updated interface with async method signatures and added CreateSessionResult class
Libraries/Opc.Ua.Server/Server/StandardServer.cs Implemented async versions of server operations and replaced Lock with SemaphoreSlim
Libraries/Opc.Ua.Server/Server/ServerInternalData.cs Added async CloseSessionAsync method
Libraries/Opc.Ua.Server/Server/IServerInternal.cs Added CloseSessionAsync method to interface
Libraries/Opc.Ua.Gds.Server.Common/GlobalDiscoverySampleServer.cs Replaced lock with SemaphoreSlim for request validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{
return [.. m_sessions.Values];
}
return [.. m_sessions.Values];
Copy link

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

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

This method accesses m_sessions without synchronization while other methods use SemaphoreSlim. This could lead to race conditions. Consider adding semaphore protection or documenting thread-safety expectations.

Suggested change
return [.. m_sessions.Values];
m_lock.Wait();
try
{
return [.. m_sessions.Values];
}
finally
{
m_lock.Release();
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

m_sessions is a concurrent dictionary internal snapshots are created on access

if (securityToken is UserNameIdentityToken)
{
lock (Lock)
SemaphoreSlim.Wait();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have an abstraction here when we expose the lock, something like ILock, then we have the opportunity to change this later, and dont repeat what we have already run into with the ubiqu SyncLock, SyncObject etc. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you expose like an AsyncLock or just a thin wrapper around semaphoreslim?

@romanett romanett self-assigned this Oct 14, 2025
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

Successfully merging this pull request may close these issues.

2 participants