Skip to content

Commit

Permalink
Use spawn instead of forkserver
Browse files Browse the repository at this point in the history
This avoids forkserver errors of the form:

OSError: AF_UNIX path too long

Bug: https://bugs.gentoo.org/941956
Signed-off-by: Zac Medico <zmedico@gentoo.org>
  • Loading branch information
zmedico committed Nov 6, 2024
1 parent c3d2596 commit 4f6c707
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ jobs:
export PYTEST_ADDOPTS="-vv -ra -l -o console_output_style=count -n $(nproc) --dist=worksteal"
# Use pytest-rerunfailures to workaround pytest-xdist worker crashes with spawn start-method (bug 924416).
[[ "${{ matrix.start-method }}" == "spawn" ]] && PYTEST_ADDOPTS+=" --reruns 5 --only-rerun 'worker .* crashed while running'"
[[ "${{ matrix.start-method }}" == "fork" ]] &&
[[ "${{ matrix.python-version }}" == "3.14-dev" ]] &&
PYTEST_ADDOPTS+=" --reruns 5 --only-rerun 'node down: Not properly terminated'"
meson test -C /tmp/build --verbose
3 changes: 3 additions & 0 deletions lib/portage/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import typing
import warnings

if multiprocessing.get_start_method() == "forkserver":
multiprocessing = multiprocessing.get_context("spawn")

import portage
from portage import os, _encodings, _unicode_decode
from portage.exception import (
Expand Down
13 changes: 9 additions & 4 deletions lib/portage/util/_async/ForkProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Distributed under the terms of the GNU General Public License v2

import fcntl
import multiprocessing
import multiprocessing as _multiprocessing
import warnings
import signal
import sys
Expand All @@ -17,6 +17,11 @@

_registered_run_exitfuncs = None

if _multiprocessing.get_start_method() == "forkserver":
multiprocessing = _multiprocessing.get_context("spawn")
else:
multiprocessing = _multiprocessing


class ForkProcess(SpawnProcess):
# NOTE: This class overrides the meaning of the SpawnProcess 'args'
Expand All @@ -33,7 +38,7 @@ class ForkProcess(SpawnProcess):
_file_names = ("connection", "slave_fd")
_files_dict = slot_dict_class(_file_names, prefix="")

_HAVE_SEND_HANDLE = getattr(multiprocessing.reduction, "HAVE_SEND_HANDLE", False)
_HAVE_SEND_HANDLE = getattr(_multiprocessing.reduction, "HAVE_SEND_HANDLE", False)

def _start(self):
if multiprocessing.get_start_method() == "fork":
Expand Down Expand Up @@ -157,7 +162,7 @@ def _send_fd_pipes(self):
(self._fd_pipes, fd_list),
)
for fd in fd_list:
multiprocessing.reduction.send_handle(
_multiprocessing.reduction.send_handle(
self._files.connection,
fd,
self.pid,
Expand Down Expand Up @@ -297,7 +302,7 @@ def _bootstrap(child_connection, have_send_handle, fd_pipes, target, args, kwarg
fd_pipes, fd_list = child_connection.recv()
fd_pipes_map = {}
for fd in fd_list:
fd_pipes_map[fd] = multiprocessing.reduction.recv_handle(
fd_pipes_map[fd] = _multiprocessing.reduction.recv_handle(
child_connection
)
child_connection.close()
Expand Down

0 comments on commit 4f6c707

Please sign in to comment.