MagicStack / MagicStack/uvloop

uvloop closes underlying sockets that were established outside upon end of asyncio.run()

オープン
#464 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Cython
スター
11.9k
フォーク
616
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供されている Unix-socket reproducer を実行し、uvloop と通常の asyncio ループを比較します。asyncio.open_unix_connection() と asyncio.run() の周辺におけるソケットの所有権とクローズのライフサイクルを追跡します。外部で作成されたソケットが asyncio.run() の後も使用可能なままであり、回帰がテストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend, networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。