-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix client Close method to properly wait for outstanding publish requests #3254
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
Conversation
|
|
…ic in CloseAsync Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3254 +/- ##
==========================================
+ Coverage 57.85% 57.91% +0.05%
==========================================
Files 365 365
Lines 79806 79882 +76
Branches 13882 13897 +15
==========================================
+ Hits 46171 46261 +90
+ Misses 29490 29479 -11
+ Partials 4145 4142 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
salihgoncu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be doing what is intended. - I have a couple of comments before going ahead and merging:
- The timeout is fixed at 5 seconds. - Wouldn't it be good to have it configurable or enforcable? - Windows Service Manager has a default timeout of 30 seconds. A service doing lots of cleanup during shutdown may cause errors in SCM.
- When the session close request comes to server, shouldn't the server invalidate any pending requests to that session? - Feels like it is more of a correct approach as the session closure can be either explicit by the client or implicit due to a loss of communication. - Regardless, the server needs to cleanup the resources. - This is just increasing the complexity at the client side.
|
Problem
The OPC UA client's
Closemethod does not properly terminate outstanding publish requests before closing the session, which violates the OPC UA standard and can lead to ServiceFault responses from the server.According to OPC UA Part 4, Section 5.6.4: "Clients are urged to wait for all outstanding requests to complete before submitting the CloseSession request."
Current Behavior
When closing a session with active subscriptions:
Expected Behavior
Before closing a session, the client should:
Solution
This PR adds proper handling of outstanding publish requests during session close:
1. New Configuration Property
Added
PublishRequestCancelWaitTimeoutproperty to control the wait behavior:2. Enhanced Close Flow
The
CloseAsyncmethod now:3. Implementation Details
WaitForOrCancelOutstandingPublishRequestsAsync()handles the wait/cancel logicCancellationTokenfor early terminationTesting
Breaking Changes
None. This change is backward compatible with a sensible default timeout of 5 seconds.
Benefits
✅ Standards Compliant: Follows OPC UA Part 4 recommendations
✅ Reduces ServiceFaults: Prevents errors from orphaned publish requests
✅ Configurable: Applications can choose the appropriate wait strategy
✅ Backward Compatible: Default behavior is a reasonable compromise
✅ Reliable: Improves client stability during shutdown
Fixes #1821
Original prompt
Fixes #1778
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.