Uploaded image for project: 'MediaPortal 2'
  1. MediaPortal 2
  2. MP2-401

Exception in Server.log when an ImportJob is finished and a new ImportJob starts

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 2.0.0-alpha.4
    • 2.0.0-alpha.3
    • None
    • None

    Description

      <p>This bug goes much deeper than it appears at first glance and is maybe also responsible for some other strange behavior that is difficult to reproduce (maybe the "somtimes the MP2 Clients takes very long until it connects with MP2 Server" bug. To be tested...)</p><p>For now it seems that the bug is in the UPnP.Infrastructure.DV.GENA.EventingState class. This class maintains a (sorted) list of scheduled UPnP event notifications. The list is instantiated as</p><pre><span class="n">SortedList</span><span class="p">&lt;</span><span class="n">DateTime</span><span class="p">,</span> <span class="n">IEnumerable</span><span class="p">&lt;</span><span class="n">DvStateVariable</span><span class="p">&gt;&gt;</span></pre><p>As you can see, tthis list is sorted by the respective DateTime when the event notification is scheduled. For each such DateTime it maintains a collection of DVStateVariables for which the respective event is scheduled.</p><p>When a DVStateVariable is changed, this list is updated and a new event for the respective DVStateVariable is added to this sorted list. This happens e.g. when an ImportJob is finished or a new ImportJob starts, but also for many other occasions. What we do in this case is the following<i> (EventingState.cs, line 114)</i>:</p><pre><span class="n">_scheduledEventNotifications</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">scheduleTime</span><span class="p">,</span> <span class="k">new</span> <span class="n">DvStateVariable</span><span class="p">[]</span> <span class="p">{</span><span class="n">variable</span><span class="p">});</span></pre><p>So we create a new array of DvStateVariables with only one entry and add it to the sorted list for the scheduled time. Something similar happens in EventingState.cs line 124. But what happens if we already have an entry in the sorted list for exactly this scheduled time? We get this exception:</p><p>[2013-10-27 10:19:49,278] [981481 ] [AMQ 'UPnPContentDirectoryServiceImpl'] [WARN ] - DvService: Error invoking StateVariableChanged delegate<br />System.ArgumentException: An entry with the same key already exists.<br />at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)<br />at System.Collections.Generic.SortedList`2.Add(TKey key, TValue value)<br />at UPnP.Infrastructure.Dv.GENA.EventingState.ModerateChangeEvent(DvStateVariable variable)<br />at UPnP.Infrastructure.Dv.GENA.EventSubscription.StateVariableChanged(DvStateVariable variable)<br />at UPnP.Infrastructure.Dv.GENA.GENAServerController.OnStateVariableChanged(DvStateVariable variable)<br />at UPnP.Infrastructure.Dv.DeviceTree.DvService.FireStateVariableChanged(DvStateVariable variable)</p><p>The reason that this bug is so difficult to reproduce is that in most cases we use DateTime.Now() as scheduled time. DateTime.Now() pretends to have an accuracy of 100 nanoseconds so it should be very unlikely that we get the same result twice when invoking DateTime.Now(). But in reality, DateTime.Now() only changes its value - depending on the respective computer - every few milliseconds. So if we have two calls to this method of EventingState one shortly after the other (e.g. when an import finishes and another import starts - in particular on a fast computer) we get the same scheduled time and, hence, the exception above.</p><p>Solution: In lines 114 and 124 of EventingState.cs we first have to check whether there is already an IEnumerable for the respective scheduled time. If it is not the case we can add one as we do now. If there is already an IEnumerable, we have to add our DvStateVariable(s) to the end of the existing IEnumerable.</p>

      Attachments

        Activity

          People

            MJGraf MJGraf (Inactive)
            MJGraf MJGraf (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: