python / python/cpython

multiprocessing.connection.Client not support IPV6

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

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

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

説明

Bug report

1、Test Code:

from multiprocessing.connection import Client
address = ('fe80::01',9999,0,0)

with Client(address,family='AF_INET6', authkey=b'1') as conn:
    print(conn.recv())

2、Error message

Traceback (most recent call last):
  File "c:\Users\Tiger\Desktop\http\c.py", line 5, in <module>
    with Client(address,family='AF_INET6', authkey=b'1') as conn:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Tiger\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\connection.py", line 501, in Client
    c = SocketClient(address)
        ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Tiger\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\connection.py", line 629, in SocketClient
    s.connect(address)
TypeError: AF_INET address must be a pair (host, port)

3、Causes and Solutions
Snippets of code in lib/multiprocessing/connection.py

def address_type(address):
    '''
    Return the types of the address

    This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    '''
    if type(address) == tuple:
        return 'AF_INET'  
    elif type(address) is str and address.startswith('\\\\'):
        return 'AF_PIPE'
    elif type(address) is str or util.is_abstract_socket_namespace(address):
        return 'AF_UNIX'
    else:
        raise ValueError('address type of %r unrecognized' % address)

An ipv6 address is a four-tuple,the code for the following sentence should be perfected

   if type(address) == tuple:
        return 'AF_INET'  

The modified code is as follows:

if type(address) == tuple:
        if len(address)==2:
            return 'AF_INET'
        else:
            return 'AF_INET6'

That's all, ok!

4、A more complete solution
"lib/multiprocessing/connection.py"

Modify the SocketClient function,add parameters family,......
def SocketClient(address,family=None):

Linked PRs
  • gh-99969

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

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

はじめの一歩

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

調査の方向性

lib/multiprocessing/connection.py と、AF_INET6 の4要素タプルを使用する、提供された Client の再現コードから始めます。address_type と SocketClient を追跡し、IPv6 の Client 接続で AF_INET のペアエラーが発生しなくなったことを確認します。この issue には、関連作業として PR gh-99969 へのリンクもあります。

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

評価

技術スタック
python
領域
networking
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

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

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