Skip to content
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

Exception while calling SignInManager.PasswordSignInAsync with npgsql provider #13

Closed
roji opened this issue Apr 14, 2016 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@roji
Copy link
Member

roji commented Apr 14, 2016

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.QueryResultScope1[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__Iterator102[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+ExceptionInterceptor1+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.EntityQueryable1[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: SimpleNullSentinelEntityKeyFactory1,
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.EntityQueryable1[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 IdentityUserRole1 userrole in value(Microsoft.Data.Entity.Query.EntityQueryable1[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] 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(EntityQueryable1[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 IdentityUserRole1 userrole in value(EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1[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.EntityQueryable1[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: SimpleNullSentinelEntityKeyFactory1,
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.QueryResultScope1[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__Iterator102[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+ExceptionInterceptor1+EnumeratorExceptionInterceptor[Identity.Model.ApplicationUser].MoveNext () [0x00000] in :0

Copied from original issue: npgsql/npgsql#788

@roji roji self-assigned this Apr 14, 2016
@roji roji added bug Something isn't working ef core labels Apr 14, 2016
@roji
Copy link
Member Author

roji commented Apr 14, 2016

From @elvisdelima on January 22, 2016 14:6

I'm having a similar exception trying to call SignInManager.PasswordSignInAsync with npgsql provider

Role role in value(Microsoft.Data.Entity.Query.Internal.EntityQueryable1[Avant.Volt.Infrastructure.CrossCutting.Authorization.AppRole]) on [userRole].RoleId equals [role].Id where [userRole].UserId.Equals(__userId_0) select [role].Name' verb: Microsoft.Data.Entity.Query.Internal.NpgsqlQueryCompilationContextFactory[3] Optimized query model: 'from IdentityUserRole1 userRole in value(Microsoft.Data.Entity.Query.Internal.EntityQueryable1[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole1[System.String]]) join AppRole role in value(Microsoft.Data.Entity.Query.Internal.EntityQueryable`1[Avant.Volt.Infrastructure.CrossCutting.Authorization.AppRole]) on [userRole].RoleId equals [role].Id where [userRole].UserId.Equals(__userId_0) select [role].Name'
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[3]
Request finished in 0.0061ms 500

fail: Microsoft.AspNet.Server.Kestrel[13]
An unhandled exception was thrown by the application.
System.ArgumentNullException: Value cannot be null.
Parameter name: entityType

     at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
     at Microsoft.Data.Entity.NpgsqlMetadataExtensions.Npgsql(IEntityType entityType)
     at Microsoft.Data.Entity.Query.ExpressionVisitors.RelationalEntityQueryableExpressionVisitor.VisitEntityQueryable(Type elementType)
     at Microsoft.Data.Entity.Query.ExpressionVisitors.ExpressionVisitorBase.Visit(Expression expression)
     at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
     at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.CompileJoinClauseInnerSequenceExpression(JoinClause joinClause, QueryModel queryModel)
     at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index)
     at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.<>c__DisplayClass61_0.<VisitJoinClause>b__0()
     at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.OptimizeJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index, Action baseVisitAction, MethodInfo operatorToFlatten, Boolean outerJoin)
     at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitJoinClause(JoinClause joinClause, QueryModel queryModel, Int32 index)
     at Remotion.Linq.QueryModelVisitorBase.VisitBodyClauses(ObservableCollection`1 bodyClauses, QueryModel queryModel)
     at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
     at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
     at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
     at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
     at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
     at Microsoft.Data.Entity.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query)
     at Microsoft.Data.Entity.Query.Internal.EntityQueryable`1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator()
     at System.Linq.AsyncEnumerable.Aggregate[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken)
     at System.Linq.AsyncEnumerable.Aggregate[TSource,TAccumulate](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, CancellationToken cancellationToken)
     at System.Linq.AsyncEnumerable.ToList[TSource](IAsyncEnumerable`1 source, CancellationToken cancellationToken)
     at Microsoft.Data.Entity.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
     at Microsoft.AspNet.Identity.EntityFramework.UserStore`4.<GetRolesAsync>d__34.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at Microsoft.AspNet.Identity.UserManager`1.<GetRolesAsync>d__100.MoveNext()

@roji
Copy link
Member Author

roji commented Apr 14, 2016

From @TheRubble on February 18, 2016 19:8

Did you ever get to the bottom of this? I'm currently affected and unsure on the best direction to take.

@roji
Copy link
Member Author

roji commented Apr 14, 2016

From @TheRubble on February 27, 2016 8:25

So I managed to find a solution to this issue. I happened to be using the rc1-update1 docker image as a base and noticed that its version of mono is outdated.

I recreated the image based upon mono version 4.2.2.30 and my initial issue was solved.

To do this either recreate and rebuild the docker file or install mono in your own docker file after the initial from statement.

Here's the command needed, I skipped the HKP part as this is done in the initial ASP.NET image.

RUN echo "deb http://download.mono-project.com/repo/debian wheezy/snapshots/4.2.2.30 main" > /etc/apt/sources.list.d/mono-xamarin.list \ && apt-get update \ && apt-get install -y mono-devel ca-certificates-mono fsharp mono-vbnc nuget \ && rm -rf /var/lib/apt/lists/*

Hope this helps someone.

@roji
Copy link
Member Author

roji commented Jun 9, 2018

Closing for age, no longer seems to be relevant.

@roji roji closed this as completed Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant