Bug 32985 - Task.delay null reference exception
Summary: Task.delay null reference exception
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 4.0.0
Hardware: Other Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-08-11 19:10 UTC by Lennartos
Modified: 2017-08-28 15:05 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Compiled Exe - single threaded (6.50 KB, application/x-msdownload)
2015-08-11 19:10 UTC, Lennartos
Details
Compiled Exe - as code example (7.50 KB, application/x-msdownload)
2015-08-11 19:13 UTC, Lennartos
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Lennartos 2015-08-11 19:10:12 UTC
System.NullReferenceException: Object reference not set to instance of an object
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() [0x00000]

Attached is code i found to be quite quick to replicate error.
Its quite synthetic, and you can remove quite a lot from it - but it takes longer and longer for the error to show.
( this one will usually fail within a minute on a raspberry PI 2 )


Complete Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MonoCrashTest
{
    class Program
    {
        static void Main(string[] args)
        {
            bool running = true;
            int loops = 0;
            Console.Clear();
            Console.WriteLine("Enter to exit - wait a few minutes for creash");
            Task.Run(async () =>
            {
                while (running)
                {
                    await Task.Run(async () =>
                    {
                        while (running)
                        {
                            try
                            {
                                System.Threading.Thread.Sleep(1);
                                await Task.Delay(1);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                    });
                }
            });
            Task.Run(async () =>
            {
                while (running)
                {
                    try
                    {
                        System.Threading.Thread.Sleep(1);
                        ++loops;
                        if ((loops % 500) == 0)
                            Console.WriteLine(loops);
                        await Task.Delay(1);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
            }
            });
            Console.ReadLine();
            running = false;
        }
    }
}
Comment 1 Lennartos 2015-08-11 19:10:38 UTC
Created attachment 12457 [details]
Compiled Exe - single threaded
Comment 2 Lennartos 2015-08-11 19:13:17 UTC
Created attachment 12458 [details]
Compiled Exe - as code example
Comment 3 Marek Safar 2015-08-14 15:11:44 UTC
I cannot reproduce it with master Mono. I hit 145500 with no errors