-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ToListAsync finished with exeptions #14737
Comments
Note for triage: I was able to reproduce (see below) but also note that the same code fails for non-async with a sufficiently large number of elements. Also, it appears to be a real command timeout, but increasing the timeout eventually leads to this:
Code: public class CounterIdentifierBase
{
public int CounterID { get; set; }
public Guid CounterGuid { get; set; }
}
public class Counter
{
public int ID { get; set; }
public Guid Guid { get; set; }
}
public class BloggingContext : DbContext
{
private static readonly LoggerFactory Logger
= new LoggerFactory(new[] { new ConsoleLoggerProvider((_, __) => true, true) });
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
//.UseLoggerFactory(Logger)
.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Test;ConnectRetryCount=0",
b => b.CommandTimeout(120));
}
public DbSet<Counter> Counters { get; set; }
public async Task<IEnumerable<CounterIdentifierBase>> GetCountersByGuid(IEnumerable<Guid> guids)
{
return await Counters
.Where(x => guids.Contains(x.Guid))
.Select(x => new CounterIdentifierBase { CounterID = x.ID, CounterGuid = x.Guid })
.ToListAsync();
}
}
public class Program
{
public static async Task Main()
{
var guids = new List<Guid>();
for (var i = 0; i < 100000; i++)
{
guids.Add(Guid.NewGuid());
}
using (var context = new BloggingContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
for (var i = 0; i < 200000; i++)
{
context.Add(new Counter
{
Guid = i % 2 == 0 ? guids[i / 2] : Guid.NewGuid()
});
}
context.SaveChanges();
}
using (var context = new BloggingContext())
{
var counters = (await context.GetCountersByGuid(guids)).ToList();
}
}
} Logs:
|
Excellent! |
@Doctormom I see the same behavior even with an index on the GUID column. |
@divega to follow up. |
@Doctormom We have a couple of issues (#13617 #13239) that discuss potential improvements to scenarios like this. It's not 100% clear that these also apply directly to this case, but it's likely that these enhancements together with some refactoring in application code will help. |
ToListAsync trows exeption when predicate Contains many items (reprodused on 10000)
When i call ToListAsync i got exeption, but when i call ToList() finished success.
Steps to reproduce
Finished with exeption:
Finished success:
Further technical details
EF Core version: 2.1.4 ,2.2.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Centos 7
IDE: Visual Studio 2017 15.9.6
The text was updated successfully, but these errors were encountered: