Repository navigation
Does RemoveSubscripiton() is need before Close() and Dispose()? #3372
Type of issue
Current BehaviorWe are experiencing some issue related with We implemented our wrapper of this package and we also implemented a "custom dispose method" that we use to dispose our lib session: public void Dispose()
{
// Remove all subscription and relative subscribed events
if (opcUaSubscription != null)
{
Console.WriteLine($"Disposing {opcUaSubscription.DisplayName} subscription..");
foreach (var monitoredItem in opcUaSubscription.MonitoredItems)
{
monitoredItem.Notification -= OnMonitoredItemNotification;
}
Console.WriteLine("Disposed")
opcUaSession?.RemoveSubscription(opcUaSubscription);
// Close session and dispose it
opcUaSession?.Close();
opcUaSession?.Dispose();
opcUaSession = null;
}My question is: Does we need to call Thanks Expected Behavior
Steps To Reproduce1- Create an app that instance 2 OPC-UA sessions Environment- OS: Windows 11
- Environment: Visual Studio 2022 17.1.4
- Runtime: .NET 6
- Nuget Version: 1.4.366.38
- Component: Opc.Ua.ClientAnything else?No response |
Replies: 1 comment
|
No, you don't need
A safe shutdown is therefore: // 1.4.x
session.Close(); // returns a StatusCode, does not throw on lost connection
session.Dispose();
// 2.0
await session.CloseAsync(closeChannel: true, ct); // also disposes the session
await session.DisposeAsync(); // harmless, e.g. via `await using`Unhooking your Closing as answered. Feel free to open an issue if |
No, you don't need
RemoveSubscriptionbefore closing. It sends aDeleteSubscriptionsrequest to the server, so it fails with an exception as soon as the connection is gone, which is exactly what you saw.Close()already covers it. It sendsCloseSessionwithdeleteSubscriptions = session.DeleteSubscriptionsOnClose(defaulttrue), so the server deletes the subscriptions together with the session. Communication errors during close are logged and returned as a status code instead of thrown.Dispose()then releases the local subscription and monitored item objects. If the server is unreachable, it cleans up the orphaned subscriptions itself when the session times out.A safe shutdown is theref…