python / python/cpython

multiprocessing.connection.Client not support IPV6

Open
#99,766 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/multiprocessing/connection.py and the supplied Client reproduction using an AF_INET6 four-tuple. Trace address_type and SocketClient, then verify that an IPv6 Client connection no longer raises the AF_INET pair error; the issue also links PR gh-99969 for related work.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.