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

Potential Deadlock #1

Open
anirudhsanthiar opened this Issue Feb 9, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@anirudhsanthiar

anirudhsanthiar commented Feb 9, 2016

Numerous wraps asynchronous methods in synchronous wrappers via the AsSync method:

  public static T AsSync<T>(this Task<T> task)
  {
    task.Wait();
    return task.Result;
  }

This method blocks on the result of an asynchronous call by calling Wait on the result.
Blocking on Task objects (Via Task.Wait() or Task.Result or Task.GetAwaiter().GetResult())
is dangerous and could result in deadlocks.
(See, for example 1 or 2).

To reproduce the deadlock, it is enough to call the following snippet suggested by Numerous' documentation from a GUI/MVC context, for example from a button click handler in a Windows Forms app.

var apiKey = "nmrs_123456789012"; 
using (var client = new NumerousClient(apiKey))
{
  var currentUser = client.GetUser().AsSync();
}

Note that the same code will not deadlock if invoked in a console app or in a unit test.
I shall be happy to supply more information in case this report is not clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment