Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to perform operation on <WriteUnixTransport closed=True reading=False 0x7f16825f8ba0 #506

Open
m0hammadhossein opened this issue Sep 28, 2022 · 3 comments

Comments

@m0hammadhossein
Copy link

  • uvloop version: 0.17.0
  • Python version: 3.10.7
  • Platform: ubuntu 20.04
  • Can you reproduce the bug with PYTHONASYNCIODEBUG in env?: yes
  • Does uvloop behave differently from vanilla asyncio? How?: yes
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pytgcalls/methods/groups/join_group_call.py", line 275, in internal_sender
    await self._binding.send(request)
  File "/usr/local/lib/python3.10/dist-packages/pytgcalls/binding.py", line 212, in send
    await self._send({
  File "/usr/local/lib/python3.10/dist-packages/pytgcalls/binding.py", line 221, in _send
    self._js_process.stdin.write(
  File "/usr/lib/python3.10/asyncio/streams.py", line 326, in write
    self._transport.write(data)
  File "uvloop/handles/stream.pyx", line 674, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <WriteUnixTransport closed=True reading=False 0x7f16825f8ba0>; the handler is closed

@kekekekule
Copy link

got the same issue with 0.16

@andrmueller
Copy link

got the issue when using aiomysql, probably the issue people are facing with aiomysql and uvloop seems to be related to this issue here.

Maybe the information posted in the aiomysql issue helps if someone takes this over.

@Kludex
Copy link

Kludex commented Oct 10, 2024

@1st1 We talked at PyCon US this year. 👋 I said I would create an issue about it... The issue is this one.

Let me share an MRE:

import asyncio


class EchoServerProtocol(asyncio.Protocol):
    def connection_made(self, transport: asyncio.Transport):  # type: ignore
        self.transport = transport

    def data_received(self, data: bytes):
        message = data.decode()
        print("Data received: {!r}".format(message))

        self.transport.close()

        # We introduce a short wait to ensure closure processing
        asyncio.ensure_future(self.write_after_closure(data))

    async def write_after_closure(self, data: bytes):
        print(self.transport)
        # uvloop: <TCPTransport closed=True reading=False 0x153e33aa0>
        # asyncio: <_SelectorSocketTransport closed fd=7>

        self.transport.write(data)
        # uvloop: RuntimeError
        # asyncio: no error

    def connection_lost(self, exc: Exception | None):
        print("The client connection lost")


async def main():
    loop = asyncio.get_running_loop()

    server = await loop.create_server(EchoServerProtocol, "127.0.0.1", 8888)

    async with server:
        await server.serve_forever()


# import uvloop
# asyncio.run(main(), loop_factory=uvloop.new_event_loop, debug=True)

asyncio.run(main())

Uncomment the lines above to see the difference in behavior.

You can use any client to call http://127.0.0.1:8888.

You can also use this small client script, if you want to try things as well...

import asyncio


async def tcp_echo_client(message: str):
    reader, writer = await asyncio.open_connection("127.0.0.1", 8888)

    print(f"Send: {message!r}")
    writer.write(message.encode())

    data = await reader.read(100)
    print(f"Received: {data.decode()!r}")

    print("Close the connection")
    writer.close()
    await writer.wait_closed()


asyncio.run(tcp_echo_client("Hello, World!"))

cc @fantix for visibility.
cc @graingert because I always ping you on asyncio related issues 👀 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants