@@ -73,6 +73,11 @@ def arbitrary_address(family):
7373 if family == 'AF_INET' :
7474 return ('localhost' , 0 )
7575 elif family == 'AF_UNIX' :
76+ # Prefer abstract sockets if possible to avoid problems with the address
77+ # size. When coding portable applications, some implementations have
78+ # sun_path as short as 92 bytes in the sockaddr_un struct.
79+ if util .abstract_sockets_supported :
80+ return f"\0 listener-{ os .getpid ()} -{ next (_mmap_counter )} "
7681 return tempfile .mktemp (prefix = 'listener-' , dir = util .get_temp_dir ())
7782 elif family == 'AF_PIPE' :
7883 return tempfile .mktemp (prefix = r'\\.\pipe\pyc-%d-%d-' %
@@ -102,7 +107,7 @@ def address_type(address):
102107 return 'AF_INET'
103108 elif type (address ) is str and address .startswith ('\\ \\ ' ):
104109 return 'AF_PIPE'
105- elif type (address ) is str :
110+ elif type (address ) is str or util . is_abstract_socket_namespace ( address ) :
106111 return 'AF_UNIX'
107112 else :
108113 raise ValueError ('address type of %r unrecognized' % address )
@@ -597,7 +602,8 @@ def __init__(self, address, family, backlog=1):
597602 self ._family = family
598603 self ._last_accepted = None
599604
600- if family == 'AF_UNIX' :
605+ if family == 'AF_UNIX' and not util .is_abstract_socket_namespace (address ):
606+ # Linux abstract socket namespaces do not need to be explicitly unlinked
601607 self ._unlink = util .Finalize (
602608 self , os .unlink , args = (address ,), exitpriority = 0
603609 )
0 commit comments