efcore: Async/wait deadlock when using “one-to-many” relationship and WebApi

I’m encountering a deadlock when use asynchronous implementation of an EF Core provider.

Say I have the following models:

public class Player
{
    public string PlayerId { get; set;}

    public string Name { get; set;}

    public List<Game> Games { get; set;}
}

public class Game
{
    public string GameId { get; set; }

    public string PlayerId { get; set; }
    public Player Player { get; set;}
}

Now I want to run the following query:

ctx.Players
.Include(p => p.Games)
.Where(p => p.PlayerId == "123")
.Select(p => new {
    PlayerId = p.PlayerId,
    Games = p.Games.ToList()
}).ToListAsync();

When I run this code via Console Application/XUnit test it works as excepted… But when I run it via ASP.Net WebApi it get into deadlock and never ends…

I used ConfigureAwait(false) all the way down in order to prevent these kind of situations but it seems that the problematic code is down underneath. I think that it might be under the System.Interactive.Async library which EFCore use - To be more specific it is under: https://github.com/Reactive-Extensions/Rx.NET/blob/develop/Ix.NET/Source/System.Interactive.Async/ToAsyncEnumerable.cs#L72 there is a call to “Result” which actually blocks the execution thread.

Does anyone encountered this behavior, maybe there is some workaround?

Notice that if I don’t load the “Games” entities then everything also works fine…

I also posted this question over Stackoverflow: http://stackoverflow.com/questions/43476290/entity-framework-core-async-wait-deadlock-when-using-one-to-many-relationship

Thanks, Tomer

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Just updating that I just released an EFCore intergration on top of Spanner: (to whom it is interested) https://github.com/NoGame/NG.Data.Spanner