OPCFoundation / UA-.NET-Legacy

OPC Foundation Unified Architecture .NET Reference Implementations
330 stars 298 forks source link

Diagnostics information uncorrectly updated on subscription number overflow #136

Closed Alex6092 closed 7 years ago

Alex6092 commented 7 years ago

In case of subscription number overflow, diagnostics information are updated with the subscription which cannot be created.

To fix it, we propose the following modification of file SampleApplications/SampleLibraries/Server/SubscriptionManager.cs, around line 574, function CreateSubscription :

                if (m_subscriptions.Count >= m_maxSubscriptionCount)
                {
                    // Delete the subscription which cannot be created :
                    subscription.Delete(context);

                    throw new ServiceResultException(StatusCodes.BadTooManySubscriptions);
                }
AlinMoldovean commented 7 years ago

A better fix would be to check the subscriptions count and reject the request before creating the subscription. Something like this:

    public virtual void CreateSubscription(
        OperationContext context,
        double           requestedPublishingInterval,
        uint             requestedLifetimeCount,
        uint             requestedMaxKeepAliveCount,
        uint             maxNotificationsPerPublish,
        bool             publishingEnabled,
        byte             priority,
        out uint         subscriptionId,
        out double       revisedPublishingInterval,
        out uint         revisedLifetimeCount,
        out uint         revisedMaxKeepAliveCount)
    {
        lock (m_lock)
        {
            if (m_subscriptions.Count >= m_maxSubscriptionCount)
            {
                throw new ServiceResultException(StatusCodes.BadTooManySubscriptions);
            }
        }

        subscriptionId = 0;
        revisedPublishingInterval = 0;