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

Publishing interval of 0 (max rate) together with non-zero HeartbeatInterval causes DivideByZero exception #1207

Closed
derSchtefan opened this issue Jun 10, 2021 · 0 comments · Fixed by #1331
Assignees
Labels
bug Something isn't working

Comments

@derSchtefan
Copy link

derSchtefan commented Jun 10, 2021

Describe the bug

When we configure a OpcPublishingInterval of 0 via publishednodes.json, and a non-zero HeartbeatInterval , a DivideByZeroException is triggered in /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 573

A publishing interval of 0 means max sampling rate / event based sampling, and is supported by the OPC UA server. (And the OPC UA standard ( https://reference.opcfoundation.org/v104/Core/docs/Part4/5.12.1/ ))

The bug appears only in conjunction with a HeartbeatInterval, and is triggered by this code:

/// /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 573
 if (m.HeartbeatInterval != null && m.HeartbeatInterval != TimeSpan.Zero) {
                        var itemKeepAliveCount = (uint)m.HeartbeatInterval.Value.TotalMilliseconds /
                            (uint)_subscription.Configuration.PublishingInterval.Value.TotalMilliseconds;
                        revisedKeepAliveCount = GreatCommonDivisor(revisedKeepAliveCount, itemKeepAliveCount);
                    }

Happens both when configured via the IIoT Stack and stand-alone via publishednodes.json .

To Reproduce

Setup a subscription (IIoT stack or standalone via publishednodes.json) that has a non-zero HeartbeatInterval and a 0 OpcPublishingInterval.

Screenshots

    [2021-06-10 13:30:30Z ERR Microsoft.Azure.IIoT.OpcUa.Protocol.Services.SubscriptionServices+SubscriptionWrapper] Failed to activate subscription
System.DivideByZeroException: Attempted to divide by zero.
   at Microsoft.Azure.IIoT.OpcUa.Protocol.Services.SubscriptionServices.SubscriptionWrapper.<>c__DisplayClass32_0.<GetSubscription>b__0(MonitoredItemModel m) in /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 573
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Microsoft.Azure.IIoT.OpcUa.Protocol.Services.SubscriptionServices.SubscriptionWrapper.GetSubscription(Session session, SubscriptionConfigurationModel configuration, Boolean activate) in /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 571
   at Microsoft.Azure.IIoT.OpcUa.Protocol.Services.SubscriptionServices.SubscriptionWrapper.ReapplyAsync(Session session, Boolean activate) in /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 259
   at Microsoft.Azure.IIoT.OpcUa.Protocol.Services.SubscriptionServices.SubscriptionWrapper.ActivateAsync(Session session) in /src/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/SubscriptionServices.cs:line 229
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants