当内存可用时,HttpWebRequest.GetResponse会抛出OutOfMemory

时间:2014-09-24 14:39:52

标签: c# .net windows winapi memory

有问题的应用程序是一个运行在~3000台机器上的Windows服务,并且对大多数机器都可以正常工作。但是在大约20台机器上,它会定期开始失败并出现未处理的OutOfMemory异常。如果我重新启动客户,则错误消失一周(直到内存使用率再次变高)。应用程序本身不会占用太多内存,并且对失败的GetResponse()的调用很小。

以下是确切的错误消息:

Insufficient memory to continue the execution of the program.

和堆栈跟踪:

at System.Net.WinHttpWebProxyFinder.GetLastWin32Error()
at System.Net.WinHttpWebProxyFinder.GetProxies(Uri destination, Uri scriptLocation, String& proxyListString)
at System.Net.WinHttpWebProxyFinder.GetProxies(Uri destination, IList`1& proxyList)
at System.Net.HybridWebProxyFinder.GetProxies(Uri destination, IList`1& proxyList)
at System.Net.AutoWebProxyScriptEngine.GetProxies(Uri destination, IList`1& proxyList, Int32& syncStatus)
at System.Net.WebProxy.GetProxiesAuto(Uri destination, Int32& syncStatus)
at System.Net.ProxyScriptChain.GetNextProxy(Uri& proxy)
at System.Net.ProxyChain.ProxyEnumerator.MoveNext()
at System.Net.ServicePointManager.FindServicePoint( Uri address, IWebProxy proxy, ProxyChain& chain, HttpAbortDelegate& abortDelegate, Int32& abortState)
at System.Net.HttpWebRequest.FindServicePoint(Boolean forceFind)
at System.Net.HttpWebRequest.GetResponse()
at ROS.RT.Client.Proxy.GetReponse(WebRequest req, Int32 tries)
at ROS.RT.Client.Proxy.GetCommands()

这是调用GetResponse()的代码:

var req = (HttpWebRequest)WebRequest.Create(url);
req.ContentType = "application/json;";
req.Method = "GET";
var res = req.GetResponse();

我在上次失败时运行了systeminfo,它显示了空闲内存

Total Physical Memory:     3,548 MB
Available Physical Memory: 1,144 MB
Virtual Memory: Max Size:  7,397 MB
Virtual Memory: Available: 2,227 MB
Virtual Memory: In Use:    5,170 MB

据我所知,应用程序本身使用了大约6MB的内存。它似乎没有达到那么远,但对Web请求的典型响应是大约1KB。

此时我告诉客户,除我的应用程序外,他们机器上的某些内容有内存泄漏,导致我的应用程序失败。但是,我并不完全了解这里发生了什么。

什么会导致WinHttpWebProxyFinder.GetProxies在有可用内存的情况下抛出OutOfMemory?

0 个答案:

没有答案
相关问题