Is using app.UseMiddleware<IServiceProvidersFeature>() not recommended?
See original GitHub issueHi team,
I found sample code on the gRPC project about not allocating request scopes: https://github.com/grpc/grpc-dotnet/blob/master/perf/benchmarkapps/GrpcAspNetCoreServer/Startup.cs
The class of interest is ServiceProvidersMiddleware.
The way i get my application to perpetually error is to:
- Start service
- Start client
- Perform one successful service call
- Restart service
- The client using the same gRPC channel now always triggers the following exception:
Connection id ““0HM3V8CGMTP5C””, Request id "“0HM3V8CGMTP5C:00000003"”: An unhandled exception was thrown by the application.
System.ObjectDisposedException: IFeatureCollection has been disposed.
Object name: ‘Collection’.
at Microsoft.AspNetCore.Http.Features.FeatureReferences1.ThrowContextDisposed() at Microsoft.AspNetCore.Http.Features.FeatureReferences
1.ContextDisposed()
at Microsoft.AspNetCore.Http.Features.FeatureReferences1.Fetch[TFeature](TFeature& cached, Func
2 factory)
at Microsoft.AspNetCore.Http.DefaultHttpResponse.set_StatusCode(Int32 value)
at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleChallengeAsync(AuthenticationProperties properties)
at Microsoft.AspNetCore.Authentication.AuthenticationHandler1.ChallengeAsync(AuthenticationProperties properties) at Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, String scheme, AuthenticationProperties properties) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication
1 application)
Can you please confirm if this error is to be expected if one uses an IServiceProvidersFeature implemenation to avoid creating the request scope?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
I would stay away from trying to do this as it breaks too many assumptions about scoped (and sometimes transient) services
That sample is a just bad implementation. I assume it existed purely for measuring a very specific use case but it’s broken as it doesn’t actually create a scoped container