python / python/cpython

create_unix_server() removes listening unix socket, potentially from other process

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

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

type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

I made a mistake leading to reusing the same unix socket path for multiple Python processes, then as a surprise realized only the last process's unix socket listening, and none will be listening if the last process stopped.

I then realized this was implemented in https://github.com/python/asyncio/pull/441 for https://bugs.python.org/issue28399 which isn't clear on why deleting the original unix socket make sense. Assumingly it is for removing old unix socket files that's not in use, but apparently it can be removing listening sockets as well.

I don't think this should be intended behavior but open to any comment. Thanks.

To reproduce, with repro.py as below:

import os
import asyncio


class IdentityProtocol(asyncio.Protocol):
    """a protocol that politely replies server's pid then close connection"""

    def connection_made(self, transport):
        print('got new connection')
        transport.write(b'hello from pid=%d\r\n' % os.getpid())
        transport.close()


async def main():
    server = await asyncio.get_running_loop().create_unix_server(
            lambda: IdentityProtocol(), 'duplicatedpath.sock'
        )
    async with server:
        await server.serve_forever()


asyncio.run(main())

run two of such instances in separate terminals for the same working directory, and after each process created, use nc -CU duplicatedpath.sock which should simply show the pid of the last python process and exit.

CPython versions tested on:

3.10

Operating systems tested on:

Linux

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

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

はじめの一歩

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

調査の方向性

まず、提供された repro.py と Linux 上の nc コマンドで動作を再現し、次に asyncio.create_unix_server() を追跡して、リンクされている PR 441 と issue 28399 を確認します。別のプロセスが listen している Unix socket を socket のクリーンアップ動作が削除しなくなり、報告されたシナリオが回帰テストでカバーされれば完了です。

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

評価

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

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

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