Hi,
we have connected Servicestack to our oauth2 server (keycloak) and it works fine.
But when we have multiple users we get connection time out because all connection pools are full.
We can see it throws an exception in
internal static async Task<IAuthSession> GetSessionInternalAsync(this IRequest httpReq, bool reload, bool async, CancellationToken token=default)
It seems that it generates alot of connections but dont release them.
Here is the stacktrace
Note: it says AspNetMembership, it’s not membership (just and old name since we migrated from that)
2023-09-06T18:02:22.014864735Z: [INFO] Error in GetSession() when ApplyPreAuthenticateFilters
2023-09-06T18:02:22.014977436Z: [INFO] 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.
2023-09-06T18:02:22.015146836Z: [INFO] at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
2023-09-06T18:02:22.015308937Z: [INFO] at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
2023-09-06T18:02:22.015324337Z: [INFO] at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
2023-09-06T18:02:22.015328737Z: [INFO] at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
2023-09-06T18:02:22.015468237Z: [INFO] at ServiceStack.OrmLite.OrmLiteConnection.Open() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteConnection.cs:line 129
2023-09-06T18:02:22.015651538Z: [INFO] at ServiceStack.OrmLite.OrmLiteConnectionFactory.OpenDbConnection() in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.OrmLite/src/ServiceStack.OrmLite/OrmLiteConnectionFactory.cs:line 98
2023-09-06T18:02:22.015801538Z: [INFO] at API.Host.MembershipProviderWrapper.GetUserProfile(String userName) in /app/API.Host/MembershipProviderWrapper.cs:line 49
2023-09-06T18:02:22.015890039Z: [INFO] at API.Host.MembershipProviderWrapper.GetUserInfo(String userName, KeyCloakRealm realm) in /app/API.Host/MembershipProviderWrapper.cs:line 96
2023-09-06T18:02:22.015992239Z: [INFO] at API.ServiceModel.Security.AspNetMembership.AspnetMembershipAuthSession.GetUserInfo(IAuthSession session, IMembershipProviderWrapper membershipWrapper, KeyCloakRealm realm) in /app/API.ServiceModel/Security/AspNetMembership/AspnetMembershipAuthSession.cs:line 46
2023-09-06T18:02:22.016115239Z: [INFO] at API.ServiceModel.Security.AspNetMembership.AspnetMembershipAuthSession.TokenToSession(IAuthSession session, JsonObject token, IRequest request) in /app/API.ServiceModel/Security/AspNetMembership/AspnetMembershipAuthSession.cs:line 109
2023-09-06T18:02:22.016279940Z: [INFO] at ServiceStack.Auth.JwtAuthProviderReader.CreateSessionFromPayload(IRequest req, JsonObject jwtPayload) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/JwtAuthProviderReader.cs:line 850
2023-09-06T18:02:22.016415240Z: [INFO] at ServiceStack.Auth.JwtAuthProviderReader.AuthenticateBearerToken(IRequest req, IResponse res, String bearerToken) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/JwtAuthProviderReader.cs:line 595
2023-09-06T18:02:22.016586441Z: [INFO] at ServiceStack.Auth.JwtAuthProviderReader.PreAuthenticateAsync(IRequest req, IResponse res) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/JwtAuthProviderReader.cs:line 541
2023-09-06T18:02:22.016739841Z: [INFO] at ServiceStack.ServiceStackHost.ApplyPreAuthenticateFiltersAsync(IRequest httpReq, IResponse httpRes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 97
2023-09-06T18:02:22.016891342Z: [INFO] at ServiceStack.ServiceExtensions.GetSessionInternalAsync(IRequest httpReq, Boolean reload, Boolean async, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/
We also retrieved this error message
ResponseStatus Object { ErrorCode: "InvalidOperationException", Message: "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.", Errors: [] }