Search code examples
pythonfastapiwindows-server-2016uvicornmcafee

OSError: [WinError 64] The specified network name is no longer available (FastAPI + Windows Server 2016 + MS SQL)


I am running a Python (FastAPI + Uvicorn) webserver on a Windows Server 2016 VM.

My application start command - uvicorn.exe main:app --port 443 --host 0.0.0.0 --ssl-keyfile PATH_TO_KEY.PEM --ssl-certfile PATH_TO_CERT.PEM

I am serving the request over HTTPS.

Although the webserver works fine, Occasionally, on some random request, it throws an OSError: [WinError 64] The specified network name is no longer available in the Powershell. And I would need to restart the entire application to start serving requests again.

OS Config:

  1. Windows Server 2016 (Version 1607, Build 14393.6167)
  2. McAfee AV + Windows Defender
  3. Connecting to MS SQL DB (different server) over ODBC 17 driver.

Stack trace -

Task exception was never retrieved
future: <Task finished name='Task-423' coro=<IocpProactor.accept.<locals>.accept_coro() done, defined at C:\Users\USERNAME
\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py:597> exception=OSError(22, 'The specified network name
is no longer available', None, 64, None)>
Traceback (most recent call last):
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 600, in accept_coro
    await future
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 772, in _register
    value = callback(None, None, ov)
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 589, in finish_acce
pt
    ov.getresult()
OSError: [WinError 64] The specified network name is no longer available
Accept failed on a socket
socket: <asyncio.TransportSocket fd=936, family=2, type=1, proto=6, laddr=('0.0.0.0', 443)>
Traceback (most recent call last):
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 843, in loop
    conn, addr = f.result()
                 ^^^^^^^^^^
OSError: [WinError 64] The specified network name is no longer available

I know it's hard to say what the issue is, But any troubleshooting/debugging tools, or software I can use, please let me know.

Articles say this issue is anti-virus related. My IT team is hesitant to disable the AntiVirus without proper proof. Could it be something else?


Solution

  • Unbeknownst to me, Powershell has the "QuickEdit" and "Insert" Mode turned on which was causing my application to freeze every time I clicked on the Powershell window which was causing network-related issues.

    Turning the QuickEdit and Insert mode off worked for me and I don't get that WinError 64 issue anymore.

    Related - https://serverfault.com/questions/204150/sometimes-powershell-stops-sending-output-until-i-press-enter-why