我发现了一个严重的bug,排查了3天,终于确定是Senparc导致的。
bbhxwl opened this issue · 6 comments
我有个项目,使用了下面的代码,软件登录偶尔就会卡很久,最长可能要10几秒,排查了数据库,云数据库,腾讯云监控都没问题,问了客服也没问题,我sql 执行也不慢。ORM库,我测试也没问题。
但是我输出了查询慢的秒数,发现只要很慢的那种,都会报一个错误。错误的行是await next();这句,这个为什么会让我的软件偶尔响应很慢?连续3天我软件偶尔使用很慢,我今天去掉了这个,软件一上午没事了。
代码如下。
app.Use(async (context, next) =>
{
var senparcSetting = context.RequestServices.GetRequiredService<IOptions<SenparcSetting>>();
var senparcWeixinSetting = context.RequestServices.GetRequiredService<IOptions<SenparcWeixinSetting>>();
var env = context.RequestServices.GetRequiredService<IWebHostEnvironment >();
// 启动 CO2NET 全局注册,必须!
var registerService = app.UseSenparcGlobal(env, senparcSetting.Value, globalRegister =>
{
}, true)
//使用 Senparc.Weixin SDK
.UseSenparcWeixin(senparcWeixinSetting.Value, (weixinRegister, setting) =>
{
weixinRegister
//注册多个公众号或小程序(可注册多个)
.RegisterWxOpenAccount(senparcWeixinSetting.Value, "adl助手");
weixinRegister.RegisterMpAccount(senparcWeixinSetting.Value.Items["通知公众号"]);
});
// 使用配置...
await next();
});
错误如下。
2023-12-13T01:39:35.001583060Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2023-12-13T01:39:35.001587238Z Connection id "0HMVR2V5D1C0N", Request id "0HMVR2V5D1C0N:00000001": An unhandled exception was thrown by the application.
2023-12-13T01:39:35.001596802Z Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unexpected end of request content.
2023-12-13T01:39:35.001601022Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.ReadAsyncInternal(CancellationToken cancellationToken)
2023-12-13T01:39:35.001605186Z at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox
1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
2023-12-13T01:39:35.001609420Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) 2023-12-13T01:39:35.002391990Z at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder
1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token) 2023-12-13T01:39:35.002406777Z at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Memory
1 buffer, CancellationToken cancellationToken)
2023-12-13T01:39:35.002411768Z at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool1 bytePool, Nullable
1 limit, CancellationToken cancellationToken)
2023-12-13T01:39:35.002416710Z at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
2023-12-13T01:39:35.002420907Z at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
2023-12-13T01:39:35.002424940Z at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
2023-12-13T01:39:35.002429199Z at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<g__Bind|0>d.MoveNext()
2023-12-13T01:39:35.002433864Z --- End of stack trace from previous location ---
2023-12-13T01:39:35.002437851Z at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2023-12-13T01:39:35.002442170Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
2023-12-13T01:39:35.002446829Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
2023-12-13T01:39:35.002450643Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
2023-12-13T01:39:35.002455513Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
2023-12-13T01:39:35.002459838Z --- End of stack trace from previous location ---
2023-12-13T01:39:35.002469536Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2023-12-13T01:39:35.002474758Z at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
2023-12-13T01:39:35.002479385Z at Program.<>c__DisplayClass0_0.<<
2023-12-13T01:39:35.002484321Z --- End of stack trace from previous location ---
2023-12-13T01:39:35.002488379Z at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
2023-12-13T01:39:35.002492867Z at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
2023-12-13T01:39:35.002496677Z at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
我看了net8例子,但是我只有Program 的顶级语句怎么写。
@bbhxwl 你这个写法不对吧?这个不是我们示例中的写法,这个注册过程只需要全局执行一次,你写在这里变成每次请求都执行了。
啊,只有Program 的怎么写,这样用了好久,别的项目能用。。。。求指点,急求大佬。
@bbhxwl 你这个写法不对吧?这个不是我们示例中的写法,这个注册过程只需要全局执行一次,你写在这里变成每次请求都执行了。
我以前是AddSenparcWeixinServices我看现在的例子是AddSenparcGlobalServices,这2个什么区别,我应该用哪个的
Global是CO2NET,就是你现在发issue的项目,Weixin是微信SDK,后者执行过程中通常包含了前者。