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

Runtime crash when debugging async code #19125

Closed
jbevain opened this issue Mar 4, 2020 · 2 comments
Closed

Runtime crash when debugging async code #19125

jbevain opened this issue Mar 4, 2020 · 2 comments
Assignees

Comments

@jbevain
Copy link
Member

jbevain commented Mar 4, 2020

Steps to Reproduce

  1. Compile:
using System;
using System.Threading;
using System.Threading.Tasks;

namespace StepOverAwait
{
	public interface IMessage
	{
	}

	public class Request : IMessage
	{
	}

	public class Reply : IMessage
	{
	}

	public class CallResult<T>
		where T : IMessage
	{
		public readonly T result;
		public CallResult(T result) => this.result = result;
	}

	public interface ICallInvoker
	{
		Task<CallResult<TReply>> InvokeAsync<TRequest, TReply>(TRequest request)
			where TRequest : IMessage, new()
			where TReply : IMessage, new();
	}

	public class CallInvoker : ICallInvoker
	{
		public async Task<CallResult<TReply>> InvokeAsync<TRequest, TReply>(TRequest request)
			where TRequest : IMessage, new()
			where TReply : IMessage, new()
		{
			await Task.Delay(1000); //if you debug and step over this, unity will crash
			return new CallResult<TReply>(new TReply());
		}
	}

	class MainClass
	{
		CancellationTokenSource cts = new CancellationTokenSource();
		ICallInvoker invoker;
		Task taskB;

		bool done;

		void Awake()
		{
			invoker = new CallInvoker();
			taskB = MethodAsync();
		}

		void Update()
		{
			if (taskB.IsCompleted)
			{
				Console.WriteLine("success");
				done = true;
			}
		}

		public static void Main(string[] args)
		{
			Console.WriteLine("Hello World!");

			var c = new MainClass();
			c.Awake();

			while (!c.done)
			{
				Thread.Sleep(1000 / 60);
				c.Update();
			}
		}

		async Task<int> MethodAsync()
		{
			var reply = await invoker.InvokeAsync<Request, Reply>(new Request());
			await Task.Delay(5);
			return 0;
		}
	}
}
  1. Put a breakpoint on the line that reads:

await Task.Delay(1000); //if you debug and step over this, unity will crash

  1. Run under the debugger, hit the breakpoint, step over.

Current Behavior

Runtime crash in get_this_async_id

* Assertion at debugger-agent.c:4547, condition `is_ok (error)' not met, function:get_this_async_id, Could not execute the method because the containing type 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[StepOverAwait.CallResult`1[TReply_REF]]', is not fully instantiated. assembly:<unknown assembly> type:<unknown type> member:(null)

Expected Behavior

No crash.

On which platforms did you notice this

[X] macOS
[] Linux
[X] Windows

Version Used:

6.6.0.166 (2019-08/d9001b5ae70 Wed Feb 12 19:20:16 EST 2020)

@thaystg thaystg self-assigned this Mar 4, 2020
@lambdageek
Copy link
Member

Probably fixed by #17727,
Looks like a duplicate of #17549

@thaystg
Copy link
Contributor

thaystg commented Mar 6, 2020

Yes, it was the same case.
I've tested and I'll close the issue.

@thaystg thaystg closed this as completed Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants