python / python/cpython

multiprocessing.connection.Client not support IPV6

未關閉
#99,766 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 lib/multiprocessing/connection.py 和使用 AF_INET6 四元組的所提供 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 摘要。