Npgsql Team,
I have developed the Web APIs in our project thru C# for .NET Core. I am using the Entity Framework Core (EFCore) with Database-First approach for database access. We use PostgreSQL database as backend for data storage. These Web APIs are called on UI application for data retrieval/save functionality. While testing the UI application, we have observed that couple of Web APIs will not return data when called for first time on UI; when we refresh the UI (pages), then the APIs will return the data for the same calls. I have verified thru Swagger also and could reproduce the issue. I have executed one Web API endpoint thru Swagger by proividing the input parameters, it does not return any data though gives 200 response code, but when I re-execute the same endpoint with same input parameters then it gives the data results. when I have checked the logs (written thru the Web APIs), then I have found the error message below for one of the Web API endpoint executed.
2020-12-24 15:39:37.478 +00:00 [ERR] ProvidersDAL->GetProviderCredentialingSummary()
System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
---> System.TimeoutException: The operation has timed out.
at Npgsql.NpgsqlTimeout.Check()
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.AllocateLong(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)
at CHC.CredentialingManager.WebAPI.DAL.Providers.ProvidersDAL.GetProviderCredentialingSummary(Nullable`1 clientID, Int64 ownerID) in D:\WebApps\CMAPI\chc.credentialingmanager.webapi1\CHC.CredentialingManager.WebAPI.DAL\Providers\ProvidersDAL.cs:line 1442
Below is the function code which is failing for above error scenario.
public async Task<IEnumerable<CredEntity>> GetProviderCredentialingSummary(long? clientID, long ownerID)
{
using (var ctx = new ProvContext())
{
try
{
// some business logic based on input parameters
NpgsqlParameter id = new NpgsqlParameter("_clientid", NpgsqlDbType.Bigint);
id.Value = (clientID.HasValue) ? clientID : DBNull.Value;
var data = await ctx.Cred.FromSqlRaw("select * from dbo.sp_getcreddata(@_id)",id).AsNoTracking().ToListAsync();
return data;
}
catch (Exception ex)
{
Logger.LogToFile.LogError(ex, String.Format("ProvidersDAL->GetProviderCredentialingSummary()"));
return null;
}
}
Here below is the DB connection string specified in appsettings.json file (API project).
"ConnectionString": {
"DBContextPostgreSQL": "host=perfdb.domain.net;port=5432;database=cmdatabase;UserId=user01;Password=pwd01;SslMode=Require;Trust Server Certificate=true;"
}
}
Am I doing anything wrong in the above code that is causing the timeout issue? I have not received this error while the Web APIs development. This is happening in performance environment (PERF) while the regression testing. Please help me to identify the issue and fix it for verification. Thank you in advance.
Npgsql Team,
I have developed the Web APIs in our project thru C# for .NET Core. I am using the Entity Framework Core (EFCore) with Database-First approach for database access. We use PostgreSQL database as backend for data storage. These Web APIs are called on UI application for data retrieval/save functionality. While testing the UI application, we have observed that couple of Web APIs will not return data when called for first time on UI; when we refresh the UI (pages), then the APIs will return the data for the same calls. I have verified thru Swagger also and could reproduce the issue. I have executed one Web API endpoint thru Swagger by proividing the input parameters, it does not return any data though gives 200 response code, but when I re-execute the same endpoint with same input parameters then it gives the data results. when I have checked the logs (written thru the Web APIs), then I have found the error message below for one of the Web API endpoint executed.
2020-12-24 15:39:37.478 +00:00 [ERR] ProvidersDAL->GetProviderCredentialingSummary()
System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
---> System.TimeoutException: The operation has timed out.
at Npgsql.NpgsqlTimeout.Check()
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.ConnectorPool.AllocateLong(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable
1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken) at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func4 operation, Func4 verifySucceeded, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.AsyncEnumerator.MoveNextAsync()at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable
1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)at CHC.CredentialingManager.WebAPI.DAL.Providers.ProvidersDAL.GetProviderCredentialingSummary(Nullable`1 clientID, Int64 ownerID) in D:\WebApps\CMAPI\chc.credentialingmanager.webapi1\CHC.CredentialingManager.WebAPI.DAL\Providers\ProvidersDAL.cs:line 1442
Below is the function code which is failing for above error scenario.
Here below is the DB connection string specified in appsettings.json file (API project).
"ConnectionString": {
"DBContextPostgreSQL": "host=perfdb.domain.net;port=5432;database=cmdatabase;UserId=user01;Password=pwd01;SslMode=Require;Trust Server Certificate=true;"
}
}
Am I doing anything wrong in the above code that is causing the timeout issue? I have not received this error while the Web APIs development. This is happening in performance environment (PERF) while the regression testing. Please help me to identify the issue and fix it for verification. Thank you in advance.