python / python/cpython

multiprocessing.connection.Client not support IPV6

Offen
#99,766 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit lib/multiprocessing/connection.py und der bereitgestellten Client-Reproduktion unter Verwendung eines AF_INET6-Vierertupels. Verfolgen Sie address_type und SocketClient, und überprüfen Sie anschließend, dass eine IPv6-Client-Verbindung nicht mehr den AF_INET-Paarfehler auslöst; der Issue verweist außerdem auf PR gh-99969 für damit verbundene Arbeiten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.