Hi,
I have my application in MVC asp.net core. My site is published on IIS. It keeps stop working after 1 or 2 days. After that i have to restart my IIS and site starts working again. I checked my logs and found the following error. Can someone please help me with this error:
ERROR 2024-05-15 08:21:59,482 [340 ] e.Diagnostics.ExceptionHandlerMiddleware - An unhandled exception has occurred while executing the request.
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 Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at Microsoft.Data.SqlClient.SqlConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction(IsolationLevel isolationLevel) at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func
3 operation, Func3 verifySucceeded) at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.BeginTransaction(DatabaseFacade databaseFacade, IsolationLevel isolationLevel) at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.CreateDbContext[TDbContext](String connectionString, IDbContextResolver dbContextResolver) at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContext[TDbContext](Nullable
1 multiTenancySide, String name)
at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase3.get_Table() at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase
3.Insert(TEntity entity)
at Abp.EntityFrameworkCore.Repositories.EfCoreRepositoryBase3.InsertAsync(TEntity entity) at Castle.Proxies.Invocations.IRepository
2_InsertAsync_29.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.DynamicProxy.AbstractInvocation.ProceedInfo.Invoke()
at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
at Abp.Auditing.AuditingHelper.SaveAsync(AuditInfo auditInfo)
at Abp.AspNetCore.Mvc.Auditing.AbpAuditActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
24 Answer(s)
-
0
Hi @huntethan89
Could you chck one of your csproj files and share your Abp.* NuGet package version ?
-
0
is your database on azure?
-
0
Hi @ismcagdas,
The Abp NuGet package version is 5.10.1.
Hi @gryphon644,
No, our database is not azure, it's on Premises.
Thanks
-
0
Hi,
Thanks. Could you upgrade your Abp NuGet packages to 6.4 and redeploy your app to see if it fixes the problem. I think you are facing a similar issue to https://github.com/aspnetboilerplate/aspnetboilerplate/pull/6165
-
0
Hi,
We upgraded the nuget package to 6.4 and in that process we faced lot of issues. So we upgraded lot of other dlls as well and that lead to one more issue as follows:
Basically what we are trying to do is fetch data from URL and showing at our end. We are passing URL in following CreateProxyHttpRequest and getting the data without any issue in version 5.10 but getting above attached image error after upgrading to 6.4.
var request = HttpContext.CreateProxyHttpRequest(new Uri(_url)); var response = await _client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, HttpContext.RequestAborted); await HttpContext.CopyProxyHttpResponse(response);
Following is the code which we are using for Proxy request:
`public static class ProxyRequest { public static HttpRequestMessage CreateProxyHttpRequest(this HttpContext context, Uri uri) { var request = context.Request;
var requestMessage = new HttpRequestMessage(); var requestMethod = request.Method; if (!HttpMethods.IsGet(requestMethod) && !HttpMethods.IsHead(requestMethod) && !HttpMethods.IsDelete(requestMethod) && !HttpMethods.IsTrace(requestMethod)) { var streamContent = new StreamContent(request.Body); requestMessage.Content = streamContent; } // Copy the request headers foreach (var header in request.Headers) { if (!requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()) && requestMessage.Content != null) { requestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); } } requestMessage.Headers.Host = uri.Authority; requestMessage.RequestUri = uri; requestMessage.Method = new HttpMethod(request.Method); return requestMessage; } public static async Task CopyProxyHttpResponse(this HttpContext context, HttpResponseMessage responseMessage) { if (responseMessage == null) { throw new ArgumentNullException(nameof(responseMessage)); } var response = context.Response; response.StatusCode = (int)responseMessage.StatusCode; foreach (var header in responseMessage.Headers) { response.Headers[header.Key] = header.Value.ToArray(); } foreach (var header in responseMessage.Content.Headers) { response.Headers[header.Key] = header.Value.ToArray(); } // SendAsync removes chunking from the response. This removes the header so it doesn't expect a chunked response. response.Headers.Remove("transfer-encoding"); using (var responseStream = await responseMessage.Content.ReadAsStreamAsync()) { await responseStream.CopyToAsync(response.Body, 1000000, context.RequestAborted); } }
}`
-
0
Hi @huntethan89
This seems like an error related to ASP.NET Core. As I can see, there are many reasons for this error, see https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about.
- Have you solved this issue ?
- Does that happen on development time ?
-
0
Hi,
Issue is not resolved yet. We tried with ASP.net Core 5.0 application without ABP and tested there with ASPNETCore.Proxy. It is working fine there but when using with ABP net zero it was not working.
-
0
Hi,
Could you share your project and steps to reproduce this issue with [email protected] ?
-
0
Hi @ismcagdas,
Project sent on email.
Thanks.
-
0
Hi @huntethan89,
We are currently reviewing your project and we found the error. We will respond as soon as possible.
-
0
Hi,
Just checking, Any update on this?
-
0
-
0
Hi,
We tried this but it did not work.
Thanks
-
0
Hi,
Could you redirect your source code to us again ? We will update the project and share it with you.
Thanks,
-
0
Hi,
Sent project in email. Please have a look.
Thanks
-
0
Hi,
Thanks, we have replied via email.
-
0
Hi,
Can you please send again. I did not receive any email.
-
0
-
0
Hi,
Our work is specifically with the action method. If you can resolve the issue for the Index action method, that would be helpful.
-
0
Hi @huntethan89
We are looking into this but couldn't find the reason yet. Could you share why do you want to use the result type
Task<IActionResult>
instead ofTask
? We can consider your use case while checking the issue. -
0
Hi, We want to use Task<IActionResult> because the function returns view as in most of the conditions. I am attaching the actual function. I hope it will help you to understand the case.
<br> <br>
public async Task<IActionResult> Index(string SclGuid, string SubGuid, string Categoryid, string bookid, string title, string bookcode, string toc, string QuotID, string QuoteCategoryid, bool IsRead)
{
if (QuotID != null && QuoteCategoryid != null && Categoryid == null)
{
Categoryid = QuoteCategoryid;
}
bool isTokenAccessExpired = false;
var AccessTokenId = "";
bool isQuoteSetting = false;
// isQuoteSetting = await isQuoteData(SubGuid);
//** This id done for user Access when user login from Openlightbox.com *//
var SubsId = SubGuid.Split("|");
if (SubsId.Length > 1)
{
try
{
AccessTokenId = HttpContext.Session.GetString("AccessTokenId").ToString();
isTokenAccessExpired = AccessTokenId == null ? true : false;
}
catch
{
return Redirect("https://openlightbox.com");
}
}
int? subscriptionId = await _entity_SchoolSubscriptionsMaster.GetAll()
.Where(x => x.SubscriptionGuid_Id == SubsId[0]).Select(x => x.SubscriptionId_FK)
.FirstOrDefaultAsync();
bool IsForTeacher = await _entity_SubscriptionMaster.GetAll().WhereIf(subscriptionId != null, x => x.Id == subscriptionId).Select(x => x.IsForTeacher).FirstOrDefaultAsync();
if (IsForTeacher && !User.Identity.IsAuthenticated)
{
return Redirect("/Account/Login?returnUrl=" + HttpContext.Request.Path.Value);
}
if (!isTokenAccessExpired)
{
TASubscriptionModel model = new TASubscriptionModel();
// model.IsQuoteSetting = isQuoteSetting;
model.IsTeacherView = IsForTeacher;
AdminQuoteSettingController quoteSetting = await QuoteSetting(SubGuid);
if (quoteSetting == null)
model.IsQuoteSetting = false;
else
{
isQuoteSetting = model.IsQuoteSetting = true;
model.Discount = quoteSetting.Discount;
var QuoteInfo = await _entity_QuoteInfo.GetAll()
.Where(x => x.QuoteSettingIDFK == quoteSetting.Id)
.WhereIf(QuotID != null && QuotID.Trim() != "", x => x.Id == Convert.ToInt32(QuotID))
.FirstOrDefaultAsync();
Tuple<int, Double> BookCountPrice = await GetBookCountPrice(model.Discount, QuoteInfo == null ? 0 : QuoteInfo.Id);
model.BookCount = BookCountPrice.Item1;
model.BookQuoteAmount = BookCountPrice.Item2.ToString();
}
try
{
string ActiveSubscriptionMessage = await _taSubscriptionAppService.IsSubscriptionActive(SubsId[0], isQuoteSetting);
if (ActiveSubscriptionMessage == "" || isQuoteSetting == true)
{
if (ActiveSubscriptionMessage != "")
{
model.SubscriptionStatus = "Past";
}
if ((Categoryid == null || Categoryid.Contains("Filter-") == true) && bookid == null)
{
if (SubsId[0] != null)
{
//model.sliderList = await _taSubscriptionAppService.GetSlidersinfo(SubGuid);
//model.tasubscriptionBooksInfo = await _taSubscriptionAppService.GetBookDataForTASubscription(SclGuid, SubGuid, "", "", "%", "-", "-", "-", 1, false, false, false);
model.advanceSearchGrades = await _taSubscriptionAppService.GetSubscriptionAdvanceFilters(SubsId[0], isQuoteSetting);
model.SchoolGuidId = SclGuid;
model.SubscriptionGuidId = SubsId[0];
model.bookResources = await _taSubscriptionAppService.GetBookResourcesIcons(SclGuid, SubsId[0]);
model.isFilterActive = false;
if (Categoryid != null)
{
string FilterToken = Categoryid.Split("Filter-")[1];
if (FilterToken.Trim() != "")
{
HttpContext.Session.Clear();
if (!string.IsNullOrWhiteSpace(AccessTokenId))
{
HttpContext.Session.SetString("AccessTokenId", AccessTokenId);
}
model.ActivefilterValues = await _taSubscriptionAppService.GetActiveFiltersdata(FilterToken);
}
}
}
return View(model);
}
else
{
var url = HttpContext.Request.GetDisplayUrl();
await TAsubscriptionBookView(Convert.ToInt32(Categoryid), Convert.ToInt32(bookid), SclGuid, SubsId[0], title, bookcode, toc, url, isQuoteSetting, QuotID, IsRead);
model.ValidsubscriptionMsg = ActiveSubscriptionMessage;
return View(model);
}
}
else
{
System.Text.RegularExpressions.Match match = Regex.Match(ActiveSubscriptionMessage, @"[A-Za-z]{3}\s\d{2},\s\d{4}");
string date = match.Value;
if (!string.IsNullOrEmpty(date))
{
var dateTime = CommonClass.GlobelDateFormat(System.DateTime.ParseExact(date, "MMM dd, yyyy", CultureInfo.CurrentCulture));
//--- Future
if (dateTime > CommonClass.GlobelDateFormat(System.DateTime.Now.Date))
{
model.SubscriptionStatus = "Future";
model.booksThumbnailsData = await _taSubscriptionAppService.GetBooksCoverImagesBySubscription(SubGuid);
}
else if (dateTime < CommonClass.GlobelDateFormat(System.DateTime.Now.Date))
{
model.SubscriptionStatus = "Past";
}
model.SubscriptionStatusDate = dateTime;
}
if (model.SubscriptionStatus == "Past")
model.ValidsubscriptionMsg = Convert.ToDateTime(model.SubscriptionStatusDate).ToString("MMMM dd, yyyy") + "| ";
else
model.ValidsubscriptionMsg = ActiveSubscriptionMessage;
return View(model);
}
}
catch (Exception ex)
{
CommonClass.Writelogs1("Error: " + ex.Message);
return View(model);
}
}
else
{
return Redirect("https://openlightbox.com");
}
}
the function `TAsubscriptionBookView` is being called in the above-mentioned index function to return the proxy URL. -
0
Hi @huntethan89,
We are still working on resolving the issue, we will get back to you as soon as possible.
-
0
Hi,
Anything on this. Please let me know.
-
0
Hi @huntethan89,
Could you try this solution?
Add wrap attribute to the class.
[WrapResult(WrapOnSuccess = false, WrapOnError = false)] public class ProxyController : ProjectDemoControllerBase { public async Task<IActionResult> Index() { var url = "the-url"; // Ensure the response is fully handled by HttpProxyAsync await this.HttpProxyAsync(url); // Return a blank result to avoid modifying the response after it has started return new EmptyResult(); } public Task ProxyToPHPServer() { return this.HttpProxyAsync("url"); } }