Memory leak in WinHttpAutoProxySvc on Windows 2008 R2 RRS feed

  • Question

  • In Windows 2008 R2, we're seeing memory growth (leak, non-release) in WinHttpAutoProxySvc.  The attached sample code, when run on Windows 2008 R2 with WinHttpAutoProxySvc enabled will cause the svchost process running WinHttpAutoProxySvc to leak memory.  If WinHttpAutoProxySvc is disabled and the server rebooted, then things run as expected and no svchost process shows undue memory growth.  Re-enabling WinHttpAutoProxySvc causes the growth to re-appear.

    This is affecting our customer's production environments, as the memory growth eventually renders the server unresponsive.

    This test does not require that the local machine have any process listening on port 8080.  The test code attempts to connect to http://<DNSHostName>:8080 repeatedly, using 15 threads (similar to our production code that has this problem), and waits 1.5 seconds between each request. 

    The .NET Code in this sample is pretty simple, and doesn't show this behavior on other server versions.  In fact, it's a vast simplification of code that has been in production and behaving itself for many years.

    using System;
    using System.Web;
    using System.Net;
    using System.Collections.Generic;
    using System.Threading;

    namespace JPLeakTest
        class Program
            static string s_url;

            static void BuildUrl()
                string host = System.Net.Dns.GetHostName();

                s_url = "http://" + host + ":8080";

            static void Main( string[] args )
                const int thread_count = 14;

                List<Thread> threads = new List<Thread>();

                for ( int i = 0; i < thread_count; ++i )
                    System.Threading.Thread t = new Thread( Operate );
                    threads.Add( t );


                foreach ( Thread t in threads )

            private static void Operate()
                while ( true )
                        Thread.Sleep( 1500 );

                        Console.WriteLine( "Calling {0}", s_url );

                        WebRequest request = WebRequest.Create( s_url );
                        request.Timeout = Timeout.Infinite;
                        request.Credentials = System.Net.CredentialCache.DefaultCredentials;

                        using ( WebResponse response = request.GetResponse() )
                            Console.WriteLine( "Loading job - shouldn't see this, nobody should be listening on 8080 for this test" );

                            // normal processing here
                    catch ( System.Threading.ThreadAbortException )
                    catch ( Exception e )
                        // Expected if there's nobody listening.
                        Console.WriteLine( "Got exception: {0}: {1}", e.GetType().ToString(), e.Message );

    Thursday, June 16, 2011 6:25 PM

All replies

  • Further note, we're running in .NET 4.0 in this case.
    Thursday, June 16, 2011 6:36 PM
  • Now versed with the same problem.

    As a temporary solution to make the service run in a separate process (SC config WinHttpAutoProxySvc type= own) and restart server, the service will restart itself periodically and memory leaks will not be.
    • Proposed as answer by belvitalik Monday, July 18, 2011 10:51 AM
    • Unproposed as answer by belvitalik Tuesday, August 16, 2011 11:54 AM
    Wednesday, July 13, 2011 7:59 AM
  • This is quite an old problem now, but I've just hit a similar issue in Windows 7. My app makes a lot of HTTP requests (about 9 per second) and the WinHttpAutoProxySvc process leaks memory at the rate of about 1GB per day. In my case it turns out to be related to auto-proxy discovery: the code is running on a desktop machine, which has the IE "Automatically detect proxy setting" tickbox checked. This also affects the behaviour of the .NET WebRequest by default, causing it to use the WinHttpAutoDiscoverySvc process. If I turn off auto-proxy in IE or set it statically in the app.config, the leak goes away.

    For me the solution has been to keep auto-proxy enabled in IE, and to do something along these lines in the app.config:

          <proxy  proxyaddress="http://a.b.c.d:e" bypassonlocal="True" />

    where a.b.c.d:e is the IP address of my web proxy. Bypassonlocal ensures that any address specificied without dots, such as "localhost" or "somelocalmachine" does not go through the proxy. This can be improved considerably, to bypass the proxy for addresses matching a regex, and I'm considering doing the whole thing in code so that I can pick up changes to the proxy address without redeployment. But the crucial point is that we're overriding the default proxy settings and thereby not using WinHttpAutoDiscoverySvc.

    This is a long way from ideal, and I regard the current behaviour as an OS bug, but at least this gives a workaround.

    ETA: After some further work, I've found the simplest solution for my circumstances is just to set WebRequest.DefaultWebProxy = null. This turns off web proxying and works fine for cases where all your requests are to a machine that does not have to be reached through a proxy.

    • Edited by Nick N Friday, March 30, 2012 2:32 PM Extra info
    Friday, March 30, 2012 10:13 AM
  • This issue has a resolution (as of April 2012).  The problem is in Jscript.dll.  Installing the latest version of IE9 resolves the issue as it has the latest Jscript.dll.  The fix was handled by the IE9 team instead of an OS hotfix.  I was researching this for a another customer and from checking our internal bug tracking systems, this is the resolution.   While this may be less than ideal for Win2008 R2 SP1 servers (who may not run IE9 on them), updating IE9 gets you the fixed Jscript.dll easy peasy for Windows 7.

    What is WinHTTP? (WinHttpautoProxysvc)

    WinHTTP implements the client HTTP stack and provides developers with a Win32 API and COM Automation component for sending HTTP requests and receiving responses. In addition, WinHTTP provides support for auto-discovering a proxy configuration via its implementation of the Web Proxy Auto-Discovery (WPAD) protocol.


    There is a hotfix available for this for just updating it, rather than having to update or install IE9.  It will be eventually available publically as hotfix article 2703157 (the article is still being written).  If you are a Premier customer you can request hotfix 2703157 from a Microsoft Premier engineer.  The hotfix is packaged for Win7/Server 2008 SP1 for Itanium, 32-bit (x86), and 64-bit (x64). 

    Tuesday, May 8, 2012 3:29 PM