Skip to content
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

Subscription not always resumed after auto reconnect #743

Open
Tyslan opened this issue Sep 12, 2024 · 1 comment
Open

Subscription not always resumed after auto reconnect #743

Tyslan opened this issue Sep 12, 2024 · 1 comment

Comments

@Tyslan
Copy link

Tyslan commented Sep 12, 2024

After auto reconnect it seems like subscriptions don't send DataChangeNotification anymore.

I was able to reproduce this issue by changing the subscribe example a little:

  1. I monitor 2 nodeIds (one does exists in the OPC UA server the other one not, which is valid for my use case)
  2. When checking the MonitoredItemsCreateResponse, I just log if there was one result that was not OK instead of panicing.

Initially I receive the DatachangeNotifications of the existing node.
If I break the connection between the OPC server and the client, I can see the the reconnection flow is followed.
But in the end I see "no subscriptions to resume" in the logs and I receive no longer DatachangeNotifications.

If you do the same with only existing nodes om the servers, you see log messages like "resuming 1 subscriptions" and "resumed 1 subscriptions"

@Tyslan
Copy link
Author

Tyslan commented Sep 13, 2024

For now the following work around seems to work for me:

I'll check if the node I want to subscribe to is a node that has a value attribute. If this check returns an error I do not add it to the MonitoredItemCreateRequest

miRequests := make([]*ua.MonitoredItemCreateRequest, 0, len(nodeIDs))
for i, nodeID := range nodeIDs {
	nid, err := ua.ParseNodeID(nodeID)
	if err != nil {
		slog.Error("Failed to parse nodeID.", "error", err)
		continue
	}
	node := client.Node(nid)
	if _, err := node.Attribute(ctx, ua.AttributeIDValue); err != nil {
		slog.Error("Node is not a value node.", "nodeID", nodeID, "error", err)
	} else {
		miRequests = append(miRequests, valueRequest(nid, uint32(i+1)))
		slog.Info("Node exists.", "nodeID", nodeID)
	}
}

res, err := subscription.Monitor(ctx, ua.TimestampsToReturnBoth, miRequests...)

I'm unsure if this is the proper way of working, but at least it fixes my problem for now.

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

No branches or pull requests

1 participant