Opened 4 months ago

Last modified 4 months ago

#3069 new defect

Race condition in AsynchronousContentView leads to exception and HL crash

Reported by: gkronber Owned by:
Priority: medium Milestone:
Component: MainForm.WindowsForms Version:
Keywords: Cc:

Description (last modified by gkronber)

There is a race condition in the AsynchronousContentView whereby in the following code 'result' is null, or already disposed within the WaitOrTimerCallback. This leads to a KeyNotFoundExceptionException in the callback and consequently a crash of HL. The error is hard to reproduce but usually occurs when algorithms are running and working with the Hive Job Manager (which often locks views and shows progress bars).

    /// Asynchronous call of GUI updating.
    /// </summary>
    /// <param name="method">The delegate to invoke.</param>
    /// <param name="args">The invoke arguments.</param>
    protected new void Invoke(Delegate method, params object[] args) {
      // prevents blocking of worker thread in Invoke, if the control is disposed
      IAsyncResult result = BeginInvoke(method, args);
      result.AsyncWaitHandle.WaitOne(1000, false);
      if (result.IsCompleted) try { EndInvoke(result); }
        catch (ObjectDisposedException) { } else {
        ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
          new WaitOrTimerCallback((x, b) => { try { EndInvoke(result); } catch (ObjectDisposedException) { } }),
          null, -1, true);
      }
    }

Change History (2)

comment:1 Changed 4 months ago by gkronber

I also observed this when importing CSV files into a regression problem.

The bug is difficult to reproduce but happens maybe once or twice a week for me.

comment:2 Changed 4 months ago by gkronber

  • Description modified (diff)
Note: See TracTickets for help on using tickets.