uvicorn: RuntimeError: unable to perform operation on

Checklist

  • The bug is reproducible against the latest release and/or master.
  • [?] There are no similar issues or pull requests to fix it yet.

Describe the bug

We are seeing frequent RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x7f25014d3810>; the handler is closed

To reproduce

Run django with latest uvicorn inside kubernetes.

Expected behavior

No error

Actual behavior

Error

Debugging material

RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x55abf67bcd50>; the handler is closed
  File "websockets/legacy/server.py", line 232, in handler
    await self.close()
  File "websockets/legacy/protocol.py", line 779, in close
    await asyncio.shield(self.close_connection_task)
  File "websockets/legacy/protocol.py", line 1309, in close_connection
    self.transport.write_eof()
  File "uvloop/handles/stream.pyx", line 696, in uvloop.loop.UVStream.write_eof
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive

Environment

  • OS / Python / Uvicorn version: ubuntu / python 3.7 / uvicorn[standard]==0.15.0
  • The exact command you’re running uvicorn with, all flags you passed included. If you run it with gunicorn please do the same. If there is a reverse-proxy involved and you cannot reproduce without it please give the minimal config of it to reproduce.

Additional context

This started happening when we started using uvicorn. In production it happens quite often:

image

There are some similar issues:

  • https://github.com/encode/uvicorn/pull/1140 - this is a issue with websockets on graceful shutdown. Considering the amount of exceptions, it seems like this is happening frequently, not just on shutdown
  • https://github.com/encode/uvicorn/issues/1229 - Someone ran into the same problem but decided to close it as an issue with websockets library. Given that the issue started occurring when we used uvicorn, I suspect an issue with uvicorn.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 10
  • Comments: 33 (5 by maintainers)

Most upvoted comments

Downgrading to websockets==10.1 resolved the issue for me.

lots of info here, a minimal reproducible example would tremendously help, I’m not able to reproduce

@ChronoDK @Muhammed-Rajab May I ask your versions of anyio, uvloop, uvicorn and httpcore which work for you? I believe this might have something to do with them.

anyio == 3.5.0 uvloop == 0.16.0 uvicorn == 0.17.6 httpcore == 0.14.7