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

DbContext.SaveChangesAsync() Method Doesn't Adhere to CommandTimeout #1600

Closed
Padagi opened this Issue Jun 13, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@Padagi

Padagi commented Jun 13, 2017

@roji requested I create a new issue in this repo based on npgsql/Npgsql.EntityFrameworkCore.PostgreSQL#198 to support of NpgsqlCommand.CommandTimeout for Async operations.

When using the DbContext.SaveChangesAsync() method, the resulting task does not adhere to the DbContext.Database.CommandTimeout value.

Steps to reproduce

I have a very simple DbContext isntance which is created by Dependency Injection:

Startup.cs:

            services.AddDbContext<apsdbContext>(options =>
            {
                options.UseNpgsql(_config["APSDB_CONNECTION"]);                
            });

And a repository that uses the context, also in Startup.cs:

            services.AddScoped<IAPSDBRepository, APSDBRepository>();

The repository receives the context via the constructor and adds results to it like this:

        private apsdbContext _context;

        public APSDBRepository(apsdbContext context)
        {
            _context = context;
        }

        public async Task<int> AddResult(Result result)
        {
            _context.Database.SetCommandTimeout(5);            
            _context.Add(result);
            return await _context.SaveChangesAsync();            
        }

After manually locking the Result table, this command never times out and deadlocks until the table lock is release.

If I change the AddResult method to the following, it times out after five seconds as expected:

        public int AddResult(Result result)
        {
            _context.Database.SetCommandTimeout(5);            
            _context.Add(result);
            return _context.SaveChanges();            
        }

Further technical details

EF Core version: 1.1.2
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL 1.1.0
Operating system: Windows 10 (Development), Windows Server 2012 R2 (Production)
IDE: VS2017 Pro

@roji

This comment has been minimized.

Show comment
Hide comment
@roji

roji Jun 9, 2018

Member

Looking at this again, I don't think we're going to do anything about making CommandTimeout work for async operations. Timeouts for async aren't supported at the socket level, and SqlClient doesn't honor CommandTimeout for async either.

Member

roji commented Jun 9, 2018

Looking at this again, I don't think we're going to do anything about making CommandTimeout work for async operations. Timeouts for async aren't supported at the socket level, and SqlClient doesn't honor CommandTimeout for async either.

@roji roji closed this Jun 9, 2018

@roji roji added the wontfix label Jun 9, 2018

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