From @ruicraveiro on September 17, 2015 0:9
Hi,
I am having an exception while using npgsql that is exclusive to this provider on EF7 (it doesn't happen with SQLite or SqlServer). The exception is the following:
error : [Microsoft.Data.Entity.Query.QueryContextFactory] An exception occurred in the database while iterating the results of a query.
System.InvalidOperationException: An operation is already in progress.
at Npgsql.NpgsqlConnector.StartUserAction (ConnectorState newState) [0x00000] in :0
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal (CommandBehavior behavior) [0x00000] in :0
at Npgsql.NpgsqlCommand.ExecuteDbDataReader (CommandBehavior behavior) [0x00000] in :0
at System.Data.Common.DbCommand.ExecuteReader () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Data.Common.DbCommand:ExecuteReader ()
at Microsoft.Data.Entity.Query.QueryingEnumerable+Enumerator.MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator102[Microsoft.Data.Entity.Storage.ValueBuffer,Microsoft.Data.Entity.Query.QueryResultScope
1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator122[Microsoft.Data.Entity.Query.QueryResultScope,Microsoft.Data.Entity.Query.QueryResultScope].MoveNext () [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10
2[Microsoft.Data.Entity.Query.QueryResultScope,Microsoft.AspNet.Identity.EntityFramework.IdentityRole].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator102[Microsoft.AspNet.Identity.EntityFramework.IdentityRole,Microsoft.AspNet.Identity.EntityFramework.IdentityRole].MoveNext () [0x00000] in <filename unknown>:0 at Microsoft.Data.Entity.Query.LinqOperatorProvider+ExceptionInterceptor
1+EnumeratorExceptionInterceptor[Microsoft.AspNet.Identity.EntityFramework.IdentityRole].MoveNext () [0x00000] in :0
This is being thrown when I'm calling:
var result = await _signInManager.PasswordSignInAsync(model.Email,
model.Password,
model.RememberMe,
lockoutOnFailure: false);
where _signInManager is a Microsoft.AspNet.Identity.SignInManager.
This bug is only visible on an old and slow Linux machine I am testing the application on (I am using Elementary OS Freya). On my recent and fast Windows machine (with an SSD), the bug is not visible. I am perfectly capable of logging in and using the application. I am not sure if this has to do with the OS or if the much better performance of my Windows machine is hiding the problem.
The log is the following (showing both aspnet and npgsql):
info : [Microsoft.Framework.DependencyInjection.DataProtectionServices] User profile is available. Using '/home/rui/.local/share/ASP.NET/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Application started. Press Ctrl+C to shut down.
warning : [Microsoft.AspNet.Mvc.Core.ControllerActionInvoker] Authorization failed for the request at filter 'Microsoft.AspNet.Mvc.AuthorizeFilter'.
info : [Microsoft.Data.Entity.Storage.Database] Compiling query model: 'from IdentityRole x in value(Microsoft.Data.Entity.Query.EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]) where [x].Name.Equals(__roleName_0) select [x] => FirstOrDefault()' info : [Microsoft.Data.Entity.Storage.Database] Optimized query model: 'from IdentityRole x in value(Microsoft.Data.Entity.Query.EntityQueryable
1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]) where [x].Name.Equals(__roleName_0) select [x] => FirstOrDefault()'
info : [Microsoft.Data.Entity.Storage.Database] Tracking query sources: [x]
info : [Microsoft.Data.Entity.Storage.Database] TRACKED: True
(QueryContext prm0, QueryResultScope prm1) => () => IAsyncEnumerable TaskToSequence(
task: Task FirstOrDefault(
source: IAsyncEnumerable _Select(
source: IAsyncEnumerable _SelectMany(
source: IAsyncEnumerable _ToSequence(
element: prm1
)
,
selector: (QueryResultScope prm1) => IAsyncEnumerable<QueryResultScope> _ShapedQuery(
queryContext: prm0,
commandBuilder: SelectExpression:
SELECT TOP(1) "x"."Id", "x"."ConcurrencyStamp", "x"."Name", "x"."NormalizedName"
FROM "AspNetRoles" AS "x"
WHERE "x"."Name" = @__roleName_0
,
shaper: (ValueBuffer prm2) => QueryResultScope CreateEntity(
querySource: from IdentityRole x in value(EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]), queryContext: prm0, parentQueryResultScope: prm1, valueBuffer: prm2, valueBufferOffset: 0, entityType: Microsoft.AspNet.Identity.EntityFramework.IdentityRole, queryStateManager: True, entityKeyFactory: SimpleNullSentinelEntityKeyFactory
1,
keyProperties: List { IdentityRole.Id, },
materializer: (ValueBuffer prm3) =>
{
var var4
var4 = new IdentityRole()
var4.Id = (string) object prm3.get_Item(0)
var4.ConcurrencyStamp = (string) object prm3.get_Item(1)
var4.Name = (string) object prm3.get_Item(2)
var4.NormalizedName = (string) object prm3.get_Item(3)
var4
}
)
)
)
,
selector: (QueryResultScope prm1) => IdentityRole prm1._GetResult(
querySource: from IdentityRole x in value(EntityQueryable`1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole])
)
)
,
cancellationToken: prm0.CancellationToken
)
)
DEBUG Opening connnection
TRACE Attempting to connect to 127.0.0.1
DEBUG Connected to 127.0.0.1:5433
DEBUG Authenticating...
TRACE Received AuthenticationRequest of type AuthenticationMD5Password
TRACE Received AuthenticationRequest of type AuthenticationOk
DEBUG ExecuteReader with CommandBehavior=Default
DEBUG [6122] ExecuteReader
TRACE [6122] Sending: [Query=SET statement_timeout = 0]
TRACE [6122] Sending: [Parse(Statement=,NumParams=0]
TRACE [6122] Sending: [Describe(Statement=)]
TRACE [6122] Sending: [Bind(Portal=,Statement=,NumParams=0]
TRACE [6122] Sending: [Execute(Portal=,MaxRows=0]
TRACE [6122] Sending: [Sync]
TRACE [6122] Array type '_aclitem' refers to unknown element with OID 1033, skipping
TRACE [6122] Array type '_oidvector' refers to unknown element with OID 30, skipping
TRACE [6122] Array type '_gtsvector' refers to unknown element with OID 3642, skipping
DEBUG ExecuteReader with CommandBehavior=Default
DEBUG [6122] ExecuteReader
TRACE [6122] Sending: [Query=SET statement_timeout = 30000]
TRACE [6122] Sending: [Parse(Statement=,NumParams=1]
TRACE [6122] Sending: [Describe(Statement=)]
TRACE [6122] Sending: [Bind(Portal=,Statement=,NumParams=1]
TRACE [6122] Sending: [Execute(Portal=,MaxRows=0]
TRACE [6122] Sending: [Sync]
DEBUG [6122] Closing connection
TRACE [6122] Really closing connection
info : [Microsoft.Data.Entity.Storage.Database] Compiling query model: 'from IdentityUserRole1 userrole in value(Microsoft.Data.Entity.Query.EntityQueryable
1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1[System.String]]) join ApplicationUser user in __p_0 on [userrole].UserId equals [user].Id where [userrole].RoleId.Equals(__role_Id_1) select [user]' info : [Microsoft.Data.Entity.Storage.Database] Optimized query model: 'from IdentityUserRole
1 userrole in value(Microsoft.Data.Entity.Query.EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole
1[System.String]]) join ApplicationUser user in __p_0 on [userrole].UserId equals [user].Id where [userrole].RoleId.Equals(__role_Id_1) select [user]'
info : [Microsoft.Data.Entity.Storage.Database] Tracking query sources: [user]
info : [Microsoft.Data.Entity.Storage.Database] TRACKED: True
(QueryContext prm0, QueryResultScope prm1) => () => IAsyncEnumerable _Select(
source: IAsyncEnumerable _Join(
outer: IAsyncEnumerable _SelectMany(
source: IAsyncEnumerable _ToSequence(
element: prm1
)
,
selector: (QueryResultScope prm1) => IAsyncEnumerable<QueryResultScope> _ShapedQuery(
queryContext: prm0,
commandBuilder: SelectExpression:
SELECT "userrole"."UserId"
FROM "AspNetUserRoles" AS "userrole"
WHERE "userrole"."RoleId" = @__role_Id_1
,
shaper: (ValueBuffer prm2) => QueryResultScope CreateValueBuffer(
querySource: from IdentityUserRole1 userrole in value(EntityQueryable
1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1[System.String]]), queryContext: prm0, parentQueryResultScope: prm1, valueBuffer: prm2, valueBufferOffset: 0 ) ) ) , inner: IAsyncEnumerable<ApplicationUser> ToAsyncEnumerable( source: IEnumerable<ApplicationUser> GetParameterValue( queryContext: prm0, parameterName: __p_0 ) ) , outerKeySelector: (QueryResultScope prm1) => (string) object ValueBuffer prm1._GetResult( querySource: from IdentityUserRole
1 userrole in value(EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole
1[System.String]])
)
.get_Item(0),
innerKeySelector: (ApplicationUser prm3) => prm3.Id,
resultSelector: (QueryResultScope prm1, ApplicationUser prm3) => QueryResultScope _Create(
querySource: join ApplicationUser user in __p_0 on [userrole].UserId equals [user].Id,
result: prm3,
parentScope: prm1
)
)
,
selector: (QueryResultScope prm1) => ApplicationUser prm1._GetResult(
querySource: join ApplicationUser user in __p_0 on [userrole].UserId equals [user].Id
)
)
info : [Microsoft.Data.Entity.Storage.Database] Compiling query model: 'value(Microsoft.Data.Entity.Query.EntityQueryable1[Identity.Model.ApplicationUser])' info : [Microsoft.Data.Entity.Storage.Database] Optimized query model: 'value(Microsoft.Data.Entity.Query.EntityQueryable
1[Identity.Model.ApplicationUser])'
info : [Microsoft.Data.Entity.Storage.Database] Tracking query sources: [_0]
info : [Microsoft.Data.Entity.Storage.Database] TRACKED: True
(QueryContext prm0, QueryResultScope prm1) => () => IEnumerable _Select(
source: IEnumerable _SelectMany(
source: IEnumerable _ToSequence(
element: prm1
)
,
selector: (QueryResultScope prm1) => IEnumerable<QueryResultScope> _ShapedQuery(
queryContext: prm0,
commandBuilder: SelectExpression:
SELECT "a"."Id", "a"."AccessFailedCount", "a"."ConcurrencyStamp", "a"."Email", "a"."EmailConfirmed", "a"."LockoutEnabled", "a"."LockoutEnd", "a"."NormalizedEmail", "a"."NormalizedUserName", "a"."PasswordHash", "a"."PhoneNumber", "a"."PhoneNumberConfirmed", "a"."SecurityStamp", "a"."TwoFactorEnabled", "a"."UserName"
FROM "AspNetUsers" AS "a"
,
shaper: (ValueBuffer prm2) => QueryResultScope CreateEntity(
querySource: from ApplicationUser _0 in value(EntityQueryable1[Identity.Model.ApplicationUser]), queryContext: prm0, parentQueryResultScope: prm1, valueBuffer: prm2, valueBufferOffset: 0, entityType: Identity.Model.ApplicationUser, queryStateManager: True, entityKeyFactory: SimpleNullSentinelEntityKeyFactory
1,
keyProperties: List { ApplicationUser.Id, },
materializer: (ValueBuffer prm3) =>
{
var var4
var4 = new ApplicationUser()
var4.Id = (string) object prm3.get_Item(0)
var4.AccessFailedCount = (int) object prm3.get_Item(1)
var4.ConcurrencyStamp = (string) object prm3.get_Item(2)
var4.Email = (string) object prm3.get_Item(3)
var4.EmailConfirmed = (bool) object prm3.get_Item(4)
var4.LockoutEnabled = (bool) object prm3.get_Item(5)
var4.LockoutEnd = (Nullable) object prm3.get_Item(6)
var4.NormalizedEmail = (string) object prm3.get_Item(7)
var4.NormalizedUserName = (string) object prm3.get_Item(8)
var4.PasswordHash = (string) object prm3.get_Item(9)
var4.PhoneNumber = (string) object prm3.get_Item(10)
var4.PhoneNumberConfirmed = (bool) object prm3.get_Item(11)
var4.SecurityStamp = (string) object prm3.get_Item(12)
var4.TwoFactorEnabled = (bool) object prm3.get_Item(13)
var4.UserName = (string) object prm3.get_Item(14)
var4
}
)
)
)
,
selector: (QueryResultScope prm1) => ApplicationUser prm1._GetResult(
querySource: from ApplicationUser _0 in value(EntityQueryable`1[Identity.Model.ApplicationUser])
)
)
DEBUG Opening connnection
DEBUG ExecuteReader with CommandBehavior=Default
DEBUG [6122] ExecuteReader
TRACE [6122] Sending: [Query=DISCARD ALL]
TRACE [6122] Sending: [Parse(Statement=,NumParams=1]
TRACE [6122] Sending: [Describe(Statement=)]
TRACE [6122] Sending: [Bind(Portal=,Statement=,NumParams=1]
TRACE [6122] Sending: [Execute(Portal=,MaxRows=0]
TRACE [6122] Sending: [Sync]
DEBUG ExecuteReader with CommandBehavior=Default
DEBUG [6122] ExecuteReader
error : [Microsoft.Data.Entity.Query.QueryContextFactory] An exception occurred in the database while iterating the results of a query.
System.InvalidOperationException: An operation is already in progress.
at Npgsql.NpgsqlConnector.StartUserAction (ConnectorState newState) [0x00000] in :0
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderInternal (CommandBehavior behavior) [0x00000] in :0
at Npgsql.NpgsqlCommand.ExecuteDbDataReader (CommandBehavior behavior) [0x00000] in :0
at System.Data.Common.DbCommand.ExecuteReader () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Data.Common.DbCommand:ExecuteReader ()
at Microsoft.Data.Entity.Query.QueryingEnumerable+Enumerator.MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator102[Microsoft.Data.Entity.Storage.ValueBuffer,Microsoft.Data.Entity.Query.QueryResultScope
1[Identity.Model.ApplicationUser]].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator122[Microsoft.Data.Entity.Query.QueryResultScope,Microsoft.Data.Entity.Query.QueryResultScope].MoveNext () [0x00000] in <filename unknown>:0 at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator10
2[Microsoft.Data.Entity.Query.QueryResultScope,Identity.Model.ApplicationUser].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator102[Identity.Model.ApplicationUser,Identity.Model.ApplicationUser].MoveNext () [0x00000] in <filename unknown>:0 at Microsoft.Data.Entity.Query.LinqOperatorProvider+ExceptionInterceptor
1+EnumeratorExceptionInterceptor[Identity.Model.ApplicationUser].MoveNext () [0x00000] in :0
Copied from original issue: npgsql/npgsql#788