MagicStack / MagicStack/uvloop
uvloop closes underlying sockets that were established outside upon end of asyncio.run()
Nobody has claimed this yet.
- Dominant language
- Cython
- Stars
- 11.9k
- Forks
- 616
- PR merge metrics
- No merged PRs in 30d
Description
This seem to be version/OS unrelated. Sample:
import asyncio
import socket
import uvloop
b = bytes('{"msg": "test"}', 'utf-8')
async def main_async(sock: socket.socket):
_, writer = await asyncio.open_unix_connection(sock=sock)
writer.write(b)
await writer.drain()
if __name__ == '__main__':
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.connect('data/sockets/echo_server.sock')
sock.sendall(b)
uvloop.install()
asyncio.run(main_async(sock)) # sock gets wrongly closed on asyncio.run() termination
sock.sendall(b) # Exception here OSError: [Errno 9] Bad file descriptor
Last line result in exception "OSError: [Errno 9] Bad file descriptor" because sock gets closed right after asyncio.run() terminates. It is wrong behavior, because sock was created outside of asyncio loop and has to be left untouched. The issue doesn't occur using regular asyncio loop.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Unix-socket reproducer and compare uvloop with the regular asyncio loop. Trace the socket ownership and close lifecycle around asyncio.open_unix_connection() and asyncio.run(); done means the externally created socket remains usable after asyncio.run() and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100