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

Connection Leaks #80

Open
briankitt opened this issue Dec 8, 2018 · 2 comments
Open

Connection Leaks #80

briankitt opened this issue Dec 8, 2018 · 2 comments

Comments

@briankitt
Copy link

briankitt commented Dec 8, 2018

I have this code implemented, and I have connection leaks.
The Dapper Server works fine for some time, but then I suddenly start getting a series of thread pool errors. I recycle the app, and it then works fine, for some time, until the cycle starts again. If I recycle on a regular basis, it never happens, but then, I would prefer to keep it up 24x7.

With only 1 user on (me), I quickly see 48 processes hanging in SQL server, the same 3 queries over and over again. I am sure this is coming from my keep alive check. I implemented the standard Identity 4 client in Angular and kept all default options.
https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.4.1/oidc-client.min.js

#1 GetRolesByUserIdQuery
(@userid int)SELECT [Name] FROM [dbo].[tblIdentityRole], [dbo].[tblIdentityUserRole] WHERE [UserId] = @userid AND [dbo].[tblIdentityRole].[Id] = [dbo].[tblIdentityUserRole].[RoleId]

#2 SelectRoleByNameQuery
(@name nvarchar(4000))SELECT * FROM [dbo].[tblIdentityRole] WHERE [Name] = @name

#3 SelectClaimByRoleQuery
(@RoleId int)SELECT [dbo].[tblIdentityRoleClaim].* FROM [dbo].[tblIdentityRole], [dbo].[tblIdentityRoleClaim] WHERE [RoleId] = @RoleId AND [dbo].[tblIdentityRoleClaim].[RoleId] = [dbo].[tblIdentityRole].[Id]

Here is a sample from my log:
[23:30:31 Error] Identity.Dapper.Repositories.RoleRepository
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
at System.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
at Identity.Dapper.Repositories.RoleRepository`4.GetClaimsByRole(TRole role, CancellationToken cancellationToken) in C:\Source\Identity4Server\Identity.Dapper\Repositories\RoleRepository.cs:line 142

[23:30:31 Error] Identity.Dapper.Stores.DapperRoleStore
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

[23:30:31 Information] IdentityServer4.Events.DefaultEventService
{
"Name": "Unhandled Exception",
"Category": "Error",
"EventType": "Error",
"Id": 3000,
"Details": "System.ArgumentNullException: Value cannot be null.\r\nParameter name: claims\r\n at System.Security.Claims.ClaimsIdentity.AddClaims(IEnumerable1 claims)\r\n at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2.GenerateClaimsAsync(TUser user)\r\n at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory1.CreateAsync(TUser user)\r\n at IdentityServer4.AspNetIdentity.UserClaimsFactory1.CreateAsync(TUser user) in C:\local\identity\server4\AspNetIdentity\src\IdentityServer4.AspNetIdentity\UserClaimsFactory.cs:line 28\r\n at STSProject.Controllers.Account.CustomProfileService.GetProfileDataAsync(ProfileDataRequestContext context) in C:\Source\Identity4Server\STSProject\Controllers\CustomProfile\CustomProfileService.cs:line 26\r\n at IdentityServer4.ResponseHandling.UserInfoResponseGenerator.ProcessAsync(UserInfoRequestValidationResult validationResult) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\ResponseHandling\UserInfoResponseGenerator.cs:line 79\r\n at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessUserInfoRequestAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 89\r\n at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 60\r\n at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\IdentityServerMiddleware.cs:line 54",
"Message": "Value cannot be null.\r\nParameter name: claims",
"ActivityId": "0HLISOTPAATCC:00000003",
"TimeStamp": "2018-12-08T05:30:31Z",
"ProcessId": 23708,
"LocalIpAddress": "::1:4242",
"RemoteIpAddress": "::1"
}

[23:30:31 Fatal] IdentityServer4.Hosting.IdentityServerMiddleware
Unhandled exception: Value cannot be null.
Parameter name: claims
System.ArgumentNullException: Value cannot be null.
Parameter name: claims
at System.Security.Claims.ClaimsIdentity.AddClaims(IEnumerable1 claims) at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2.GenerateClaimsAsync(TUser user)
at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory1.CreateAsync(TUser user) at IdentityServer4.AspNetIdentity.UserClaimsFactory1.CreateAsync(TUser user) in C:\local\identity\server4\AspNetIdentity\src\IdentityServer4.AspNetIdentity\UserClaimsFactory.cs:line 28
at STSProject.Controllers.Account.CustomProfileService.GetProfileDataAsync(ProfileDataRequestContext context) in C:\Source\Identity4Server\STSProject\Controllers\CustomProfile\CustomProfileService.cs:line 26
at IdentityServer4.ResponseHandling.UserInfoResponseGenerator.ProcessAsync(UserInfoRequestValidationResult validationResult) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\ResponseHandling\UserInfoResponseGenerator.cs:line 79
at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessUserInfoRequestAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 89
at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 60
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\IdentityServerMiddleware.cs:line 54

[23:30:31 Error] Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
An unhandled exception has occurred while executing the request.
System.ArgumentNullException: Value cannot be null.
Parameter name: claims
at System.Security.Claims.ClaimsIdentity.AddClaims(IEnumerable1 claims) at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory2.GenerateClaimsAsync(TUser user)
at Microsoft.AspNetCore.Identity.UserClaimsPrincipalFactory1.CreateAsync(TUser user) at IdentityServer4.AspNetIdentity.UserClaimsFactory1.CreateAsync(TUser user) in C:\local\identity\server4\AspNetIdentity\src\IdentityServer4.AspNetIdentity\UserClaimsFactory.cs:line 28
at STSProject.Controllers.Account.CustomProfileService.GetProfileDataAsync(ProfileDataRequestContext context) in C:\Source\Identity4Server\STSProject\Controllers\CustomProfile\CustomProfileService.cs:line 26
at IdentityServer4.ResponseHandling.UserInfoResponseGenerator.ProcessAsync(UserInfoRequestValidationResult validationResult) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\ResponseHandling\UserInfoResponseGenerator.cs:line 79
at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessUserInfoRequestAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 89
at IdentityServer4.Endpoints.UserInfoEndpoint.ProcessAsync(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Endpoints\UserInfoEndpoint.cs:line 60
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\IdentityServerMiddleware.cs:line 54
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\IdentityServerMiddleware.cs:line 69
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context) in C:\local\identity\server4\IdentityServer4\src\IdentityServer4\Hosting\BaseUrlMiddleware.cs:line 36
at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Joonasw.AspNetCore.SecurityHeaders.Csp.CspMiddleware.Invoke(HttpContext context)
at STSProject.Startup.<>c.<b__8_0>d.MoveNext() in C:\Source\Identity4Server\STSProject\Startup.cs:line 119
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

[23:30:31 Debug] IdentityServer4.Hosting.CorsPolicyProvider
CORS request made for path: /Home/Error from origin: http://localhost:4200 but was ignored because path was not for an allowed IdentityServer CORS endpoint

[23:30:51 Error] Identity.Dapper.Repositories.UserRepository
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
at System.Data.Common.ADP.ExceptionWithStackTrace(Exception e)
--- End of stack trace from previous location where exception was thrown ---
at Identity.Dapper.Repositories.UserRepository`7.GetByIdAsync(TKey id) in C:\Source\Identity4Server\Identity.Dapper\Repositories\UserRepository.cs:line 133

@grandchamp
Copy link
Owner

Did you managed to find anything? I guess that all the disposals are made by the internal IoC. But maybe i'm not using connections properly.
I'm not having too much time (you can guess by the time i took to answer your question) to work on this, but i'll be very appreciated if you can find something on the code and make a pull request.

@briankitt
Copy link
Author

briankitt commented Feb 19, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants