Open Closed

Problem with dbContext.SessionHandle = null in DeleteDirectAsync method #6114


User avatar
0
dev3.advantiss created

Hello, I use Identity Server... After upgrade ABP from 5.3.3 to 7.3.1 I have a problem... The repositories MongoDeviceFlowCodesRepository and MongoPersistentGrantRepository invoke method DeleteDirectAsync { .... await collection.DeleteManyAsync( dbContext.SessionHandle, Builders<PersistedGrant>.Filter.Where(predicate), cancellationToken: cancellationToken ); .... }

but dbContext.SessionHandle = null and that method is crashed

I replaced these Repositories, so I will not use dbContext.SessionHandle if it is null.

this code appeared in 7.3.1,

  1. why you start using dbContext.SessionHandle?
  2. what is best decision for solve this problem?
  • ABP Framework version: v7.3.1
  • UI Type: Angular
  • Database System: MongoDB
  • Exception message and full stack trace: 2023-11-01 03:10:13.137 +00:00 [ERR] Job DEFAULT.Volo.Abp.IdentityServer.Tokens.TokenCleanupBackgroundWorker threw an unhandled Exception: System.ArgumentNullException: Value cannot be null. (Parameter 'session') at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName) at MongoDB.Driver.MongoCollectionImpl1.BulkWriteAsync(IClientSessionHandle session, IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionBase1.DeleteManyAsync(FilterDefinition1 filter, DeleteOptions options, Func3 bulkWriteFuncAsync) at Volo.Abp.Domain.Repositories.MongoDB.MongoDbRepository2.DeleteDirectAsync(Expression1 predicate, CancellationToken cancellationToken) at Volo.Abp.IdentityServer.MongoDB.MongoPersistentGrantRepository.DeleteExpirationAsync(DateTime maxExpirationDate, CancellationToken cancellationToken) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.RemoveGrantsAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.CleanAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupBackgroundWorker.DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) at Volo.Abp.BackgroundWorkers.Quartz.QuartzPeriodicBackgroundWorkerAdapter1.Execute(IJobExecutionContext context) at Quartz.Core.JobRunShell.Run(CancellationToken cancellationToken) 2023-11-01 03:10:13.226 +00:00 [ERR] Job DEFAULT.Volo.Abp.IdentityServer.Tokens.TokenCleanupBackgroundWorker threw an exception. Quartz.SchedulerException: Job threw an unhandled exception. ---> System.ArgumentNullException: Value cannot be null. (Parameter 'session') at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName) at MongoDB.Driver.MongoCollectionImpl1.BulkWriteAsync(IClientSessionHandle session, IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionBase1.DeleteManyAsync(FilterDefinition1 filter, DeleteOptions options, Func3 bulkWriteFuncAsync) at Volo.Abp.Domain.Repositories.MongoDB.MongoDbRepository2.DeleteDirectAsync(Expression1 predicate, CancellationToken cancellationToken) at Volo.Abp.IdentityServer.MongoDB.MongoPersistentGrantRepository.DeleteExpirationAsync(DateTime maxExpirationDate, CancellationToken cancellationToken) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.RemoveGrantsAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.CleanAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupBackgroundWorker.DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) at Volo.Abp.BackgroundWorkers.Quartz.QuartzPeriodicBackgroundWorkerAdapter1.Execute(IJobExecutionContext context) at Quartz.Core.JobRunShell.Run(CancellationToken cancellationToken) --- End of inner exception stack trace --- [See nested exception: System.ArgumentNullException: Value cannot be null. (Parameter 'session') at MongoDB.Driver.Core.Misc.Ensure.IsNotNull[T](T value, String paramName) at MongoDB.Driver.MongoCollectionImpl1.BulkWriteAsync(IClientSessionHandle session, IEnumerable1 requests, BulkWriteOptions options, CancellationToken cancellationToken) at MongoDB.Driver.MongoCollectionBase1.DeleteManyAsync(FilterDefinition1 filter, DeleteOptions options, Func3 bulkWriteFuncAsync) at Volo.Abp.Domain.Repositories.MongoDB.MongoDbRepository2.DeleteDirectAsync(Expression1 predicate, CancellationToken cancellationToken) at Volo.Abp.IdentityServer.MongoDB.MongoPersistentGrantRepository.DeleteExpirationAsync(DateTime maxExpirationDate, CancellationToken cancellationToken) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.RemoveGrantsAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupService.CleanAsync() at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapter.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Volo.Abp.IdentityServer.Tokens.TokenCleanupBackgroundWorker.DoWorkAsync(PeriodicBackgroundWorkerContext workerContext) at Volo.Abp.BackgroundWorkers.Quartz.QuartzPeriodicBackgroundWorkerAdapter1.Execute(IJobExecutionContext context) at Quartz.Core.JobRunShell.Run(CancellationToken cancellationToken)]

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    why you start using dbContext.SessionHandle?

    You can take a look at this PR https://github.com/abpframework/abp/pull/5174

    what is best decision for solve this problem?

    You should use the session as you can.

  • User Avatar
    0
    dev3.advantiss created

    Hi

    so, Is it normal "I replaced these Repositories, so I will not use dbContext.SessionHandle if it is null"?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Keep your repository the same as abp will be best.

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35