IIS forcibly terminates backend TCP connections (WinError 64) when reverse proxying to long-running Python server on Windows

Amjad Almaqbali 20 Reputation points
2026-01-29T07:00:19.8666667+00:00

I am experiencing repeated and unexpected backend connection terminations when using IIS as a reverse proxy to a locally running Python web server on Windows.

Environment

Operating System: Windows (desktop/server)

Web Server: IIS

  • Reverse proxy to a backend service running on 127.0.0.1:8000

Backend application: Python web application (ASGI-based)

Python version: 3.13

The backend server is running normally and listening on the local interface

Problem Description

After the application runs for some time, IIS forcibly closes the backend TCP socket. When this happens, the Python server logs the following error:

OSError: [WinError 64] The specified network name is no longer available
Accept failed on a socket
Task exception was never retrieved

This is the web.config I currently use:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="StaticFile" />
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="C:\Inetpub\vhosts\test.dmmn.com\httpdocs\env\Scripts\python.exe" 
	arguments="-m uvicorn backend.main:app --host 127.0.0.1 --port %HTTP_PLATFORM_PORT%" 
	stdoutLogEnabled="true" stdoutLogFile="C:\Inetpub\vhosts\test.dmmn.com\httpdocs\logs\stdout.log">
      <environmentVariables>
        <environmentVariable name="PYTHONPATH" value="C:\Inetpub\vhosts\test.dmmn.com\httpdocs" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
  <system.web>
    <compilation tempDirectory="C:\Inetpub\vhosts\test.dmmn.com\httpdocs\tmp" />
  </system.web>
</configuration>

Windows development | Internet Information Services
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tom Tran (WICLOUD CORPORATION) 3,930 Reputation points Microsoft External Staff Moderator
    2026-01-29T09:51:49.4933333+00:00

    Hi @Amjad Almaqbali , Thanks for sharing your details!

    I took a closer look at the behavior you’re seeing where IIS suddenly closes the connection to your backend Python server and your logs show:

    • OSError: [WinError 64] The specified network name is no longer available

    From what I can tell, this doesn’t point to an issue in your Python app. I believe what’s happening is that IIS is closing the backend TCP connection earlier than your ASGI server expects, so Uvicorn continues trying to use a socket that IIS has already dropped.


    httpPlatformHandler will start your Python process and forward requests to it, but I think it’s important to note that it isn’t a full reverse proxy. It doesn’t give much control over backend connection lifetime, buffering, or long‑running async requests. Because Uvicorn often keeps connections alive longer than IIS’s defaults, IIS may decide that the backend request is “done” or “expired” and close the TCP connection:

    • IIS forwards the request to your Python backend correctly.
    • But if a connection stays open too long (long async work, idle period, or slow-running handler), I believe IIS may close it based on its internal timeout rules.
    • When IIS closes the socket, Uvicorn tries to continue using it, which triggers WinError 64.

    I also don’t think this is a Uvicorn issue, it’s more about how IIS manages backend connections in this setup.


    Perhaps you could try out these suggestions first:

    1. Increase httpPlatformHandler timeout values

    I think increasing values like processTimeout and startupTimeLimit helps IIS avoid treating the backend process as unresponsive. This can reduce early connection drops.

    2. Consider using ARR + URL Rewrite instead of httpPlatformHandler

    If you want a more stable reverse proxy layer inside IIS, I suggest looking at Application Request Routing (ARR) with URL Rewrite. ARR provides proper proxy features like connection lifetime control and health management. This is also reflected in Microsoft’s ARR troubleshooting and configuration documentation here:

    3. Use a dedicated reverse proxy if the setup allows it

    If there’s flexibility, I think using NGINX or HAProxy in front of Uvicorn is usually the most stable approach. These tools handle long-lived keep-alive connections and async workloads much more predictably than IIS’s built-in forwarding.


    Hope this helps! If you have any questions, please feel free to comment below. I'll be happy to assist!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.