环境:
本机功能测试没发现。
测试环境测试没发现。
正式环境,不断出现。
异常信息如下:
异常层级:0
错误信息:null“MediaTypeFormatter”无效。
Parameter name: formatters
异常对象:System.Net.Http.Formatting
错误堆栈: at System.Net.Http.Formatting.MediaTypeFormatterCollection.VerifyAndSetFormatters(IEnumerable`1 formatters)
at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)
at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)
at System.Web.Http.ModelBinding.FormatterParameterBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()异常方法:Void VerifyAndSetFormatters(System.Collections.Generic.IEnumerable`1[System.Net.Http.Formatting.MediaTypeFormatter])
异常数据:{}
结果是,多次异常后:应用程序池有可能停止。
分析:从异常信息后,是有初始化参数时,无法正常接收分析参数导致的。
百度一下:无任何相关信息(谷哥也没有)。看来问题,比较SB别人都不会犯这个错。
为什么本机和测试中没出现?1运行环境有问题2代码有问题
正式环境之前的版本是正常的,所以应该可以排除。那么就是代码有问题。
可排查了好久,没能发现问题在那。
那本地和正式的有何不同?并发
找原因方法:并发测试
本地是没有并发测试的,正式并发大。所以只好模拟并发请求相关接口。
结果-----内存溢出。我X。
我这里提web api (你的可能不一样呢)
其中有如下代码
protected override void Initialize(HttpControllerContext controllerContext)
{
controllerContext.Configuration.Formatters.Add(new FileMediaFormatter());
base.Initialize(controllerContext);
}
没相到这个不是基于请求的,它会一直累加。(为什么?希望大神,来说明下---)
解决方法:1将这个添加放在全局(我这里好像不行,会导致其它问题)
2确保不累加进去。方法就不说了。
结论:找Bug也是一下痛苦的事。
第一个文章,希望是个好开始。