Add fix for cases where sockname len > 100

Guillermo Rodriguez 2025-04-17 12:07:40 -03:00
parent 6c24787f77
commit a49dbc7b97
No known key found for this signature in database
GPG Key ID: 002CC5F1E6BDA53E
1 changed files with 21 additions and 0 deletions

View File

@ -22,6 +22,7 @@ https://github.com/python/cpython/blob/275056a7fdcbe36aaac494b4183ae59943a338eb/
import os import os
import array import array
import tempfile import tempfile
from uuid import uuid4
from pathlib import Path from pathlib import Path
from typing import AsyncContextManager from typing import AsyncContextManager
from contextlib import asynccontextmanager as acm from contextlib import asynccontextmanager as acm
@ -273,6 +274,26 @@ async def request_fds_from(
f'{fds_name}-from-{actor_name}-to-{this_actor.name}.sock' f'{fds_name}-from-{actor_name}-to-{this_actor.name}.sock'
) )
# having a socket path length > 100 aprox can cause:
# OSError: AF_UNIX path too long
# https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html#tag_13_67_04
# attempt sock path creation with smaller names
if len(sock_path) > 100:
sock_path = str(
Path(tempfile.gettempdir())
/
f'{fds_name}-to-{this_actor.name}.sock'
)
if len(sock_path) > 100:
# just use uuid4
sock_path = str(
Path(tempfile.gettempdir())
/
f'pass-fds-{uuid4()}.sock'
)
async with ( async with (
tractor.find_actor(actor_name) as portal, tractor.find_actor(actor_name) as portal,