Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 468990 - >=sys-apps/portage-2.2.0_alpha174: OSError: [Errno 13] Permission denied: '/var/tmp/portage/app-admin/syslog-ng-3.4.1/.ipc_lock' due to race between root EbuildIpcDaemon and non-root EbuildIpc
Summary: >=sys-apps/portage-2.2.0_alpha174: OSError: [Errno 13] Permission denied: '/v...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Portage team
URL: https://issuetracker.google.com/issue...
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2013-05-08 05:22 UTC by Samuli Suominen (RETIRED)
Modified: 2022-04-11 20:26 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuli Suominen (RETIRED) gentoo-dev 2013-05-08 05:22:21 UTC
Portage 2.2.0_alpha174 (default/linux/amd64/13.0/developer, gcc-4.8.0, glibc-2.17, 3.8.6 x86_64)
=================================================================
System uname: Linux-3.8.6-x86_64-Intel-R-_Core-TM-_i5-2400_CPU_@_3.10GHz-with-gentoo-2.2
KiB Mem:    16396528 total,   9640032 free
KiB Swap:    1048572 total,   1048572 free
Timestamp of tree: Unknown
ld GNU ld (GNU Binutils) 2.23.2
app-shells/bash:          4.2_p45
dev-java/java-config:     2.2.0
dev-lang/python:          2.7.4, 3.2.4
dev-util/cmake:           2.8.10.2-r2
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.11.8
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.13, 2.69
sys-devel/automake:       1.11.6, 1.13.1
sys-devel/binutils:       2.23.2
sys-devel/gcc:            4.8.0
sys-devel/gcc-config:     1.8
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.9 (virtual/os-headers)
sys-libs/glibc:           2.17
Repositories:

gentoo
    location: /home/ssuominen/gentoo-x86
    sync: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

local
    location: /usr/local/portage
    masters: gentoo
    priority: 0

ABI="amd64"
ABI_X86="32 64"
ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
ACCEPT_PROPERTIES="*"
ACCEPT_RESTRICT="*"
ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci"
ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol"
ANT_HOME="/usr/share/ant"
APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias"
ARCH="amd64"
AUTOCLEAN="yes"
BC_ENV_ARGS="-l"
BOOTSTRAP_USE="cxx unicode python_targets_python3_2 python_targets_python2_7 multilib"
CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author"
CAMERAS="ptp2"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CFLAGS_amd64="-m64"
CFLAGS_x32="-mx32"
CFLAGS_x86="-m32"
CHOST="x86_64-pc-linux-gnu"
CHOST_amd64="x86_64-pc-linux-gnu"
CHOST_x32="x86_64-pc-linux-gnux32"
CHOST_x86="i686-pc-linux-gnu"
CLEAN_DELAY="0"
COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
COLLISION_IGNORE="/lib/modules/* *.py[co] *$py.class"
COLORTERM="xfce4-terminal"
CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CURL_SSL="nss"
CVS_RSH="ssh"
CXXFLAGS="-march=native -O2 -pipe"
DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-4z1Msn2vLP,guid=feb816f60e57cac3475ab41f5184bbad"
DEFAULT_ABI="amd64"
DESKTOP_SESSION="xfce"
DISPLAY=":0.0"
DISTDIR="/home/ssuominen/gentoo-x86/distfiles"
ECHANGELOG_USER="Samuli Suominen <ssuominen@gentoo.org>"
EDITOR="/bin/nano"
ELIBC="glibc"
EMERGE_DEFAULT_OPTS="--quiet-build=n --verbose --tree"
EMERGE_WARNING_DELAY="0"
EPREFIX=""
EROOT="/"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs protect-owned sandbox sfperms sign strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox"
FETCHCOMMAND="wget -t 3 -T 60 --passive-ftp -O "${DISTDIR}/${FILE}" "${URI}""
FETCHCOMMAND_RSYNC="rsync -avP "${URI}" "${DISTDIR}/${FILE}""
FETCHCOMMAND_SFTP="bash -c "x=\${2#sftp://} ; host=\${x%%/*} ; port=\${host##*:} ; host=\${host%:*} ; [[ \${host} = \${port} ]] && port=22 ; exec sftp -P \${port} \"\${host}:/\${x#*/}\" \"\$1\"" sftp "${DISTDIR}/${FILE}" "${URI}""
FETCHCOMMAND_SSH="bash -c "x=\${2#ssh://} ; host=\${x%%/*} ; port=\${host##*:} ; host=\${host%:*} ; [[ \${host} = \${port} ]] && port=22 ; exec rsync --rsh=\"ssh -p\${port}\" -avP \"\${host}:/\${x#*/}\" \"\$1\"" rsync "${DISTDIR}/${FILE}" "${URI}""
FFLAGS="-O2 -pipe"
FLTK_DOCDIR="/usr/share/doc/fltk-1.3.2/html"
GCC_SPECS=""
GENTOO_MIRRORS="http://distfiles.gentoo.org"
GLADE_CATALOG_PATH=":"
GLADE_MODULE_PATH=":"
GLADE_PIXMAP_PATH=":"
GPG_AGENT_INFO="/tmp/gpg-cWecui/S.gpg-agent:1112:1"
GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx"
GRUB_PLATFORMS=""
GSETTINGS_BACKEND="dconf"
GUILE_LOAD_PATH="/usr/share/guile/1.8"
HG="/usr/bin/hg"
HOME="/home/ssuominen"
HUSHLOGIN="FALSE"
INFOPATH="/usr/share/info:/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.23.2/info"
INPUT_DEVICES="evdev"
IUSE_IMPLICIT="prefix"
I_AM_CRAZY_TO_USE_MASKED_VERSIONS="1"
I_KNOW_WHAT_I_AM_DOING="yes"
JAVAC="/etc/java-config-2/current-system-vm/bin/javac"
JAVA_HOME="/etc/java-config-2/current-system-vm"
JDK_HOME="/etc/java-config-2/current-system-vm"
KERNEL="linux"
LADSPA_PATH="/usr/lib64/ladspa"
LANG="en_US.UTF-8"
LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text"
LC_CTYPE="fi_FI.UTF-8"
LC_TIME="en_GB.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
LDFLAGS_amd64="-m elf_x86_64"
LDFLAGS_x32="-m elf32_x86_64"
LDFLAGS_x86="-m elf_i386"
LESS="-R -M --shift 5"
LESSOPEN="|lesspipe %s"
LIBDIR_amd64="lib64"
LIBDIR_amd64_fbsd="lib64"
LIBDIR_n32="lib32"
LIBDIR_n64="lib64"
LIBDIR_o32="lib"
LIBDIR_ppc="lib32"
LIBDIR_ppc64="lib64"
LIBDIR_s390="lib32"
LIBDIR_s390x="lib64"
LIBDIR_sparc32="lib32"
LIBDIR_sparc64="lib64"
LIBDIR_x32="libx32"
LIBDIR_x86="lib32"
LIBDIR_x86_fbsd="lib32"
LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer"
LINGUAS="en"
LOGNAME="ssuominen"
MAIL="/var/mail/ssuominen"
MAKEOPTS="-j9"
MANPATH="/etc/java-config-2/current-system-vm/man:/usr/local/share/man:/usr/share/man:/usr/share/gcc-data/x86_64-pc-linux-gnu/4.8.0/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.23.2/man:/etc/java-config-2/current-system-vm/man/"
MULTILIB_ABIS="amd64 x86"
MULTILIB_STRICT_DENY="64-bit.*shared object"
MULTILIB_STRICT_DIRS="/lib32 /lib /usr/lib32 /usr/lib /usr/kde/*/lib32 /usr/kde/*/lib /usr/qt/*/lib32 /usr/qt/*/lib /usr/X11R6/lib32 /usr/X11R6/lib"
MULTILIB_STRICT_EXEMPT="(perl5|gcc|gcc-lib|binutils|eclipse-3|debug|portage|udev)"
NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
OFFICE_IMPLEMENTATION="libreoffice"
OPENCL_PROFILE="nvidia"
OPENGL_PROFILE="nvidia"
PAGER="/usr/bin/less"
PATH="/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.0:/usr/games/bin"
PHP_TARGETS="php5-3"
PKGDIR="/usr/portage/packages"
PORTAGE_ARCHLIST="ppc sparc64-freebsd ppc-openbsd x86-openbsd ppc64 x86-winnt x86-fbsd ppc-aix alpha arm x86-freebsd s390 amd64 arm-linux x86-macos x64-openbsd ia64-hpux hppa x86-netbsd ppc64-linux x86-cygwin amd64-linux ia64-linux x86 sparc-solaris x64-freebsd sparc64-solaris x86-linux x64-macos sparc m68k-mint ia64 mips ppc-macos x86-interix hppa-hpux amd64-fbsd x64-solaris m68k sh x86-solaris sparc-fbsd"
PORTAGE_BIN_PATH="/usr/lib64/portage/bin"
PORTAGE_COMPRESS_EXCLUDE_SUFFIXES="css gif htm[l]? jp[e]?g js pdf png"
PORTAGE_CONFIGROOT="/"
PORTAGE_DEBUG="0"
PORTAGE_DEPCACHEDIR="/var/cache/edb/dep"
PORTAGE_ELOG_CLASSES="log warn error qa"
PORTAGE_ELOG_MAILFROM="portage@localhost"
PORTAGE_ELOG_MAILSUBJECT="[portage] ebuild log for ${PACKAGE} on ${HOST}"
PORTAGE_ELOG_MAILURI="root"
PORTAGE_ELOG_SYSTEM="save_summary:log,warn,error,qa echo"
PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS="5"
PORTAGE_FETCH_RESUME_MIN_SIZE="350K"
PORTAGE_GID="250"
PORTAGE_GPG_DIR="/home/ssuominen/.gnupg"
PORTAGE_GPG_KEY="4868F14D"
PORTAGE_GPG_SIGNING_COMMAND="gpg --sign --digest-algo SHA256 --clearsign --yes --default-key "${PORTAGE_GPG_KEY}" --homedir "${PORTAGE_GPG_DIR}" "${FILE}""
PORTAGE_INST_GID="0"
PORTAGE_INST_UID="0"
PORTAGE_INTERNAL_CALLER="1"
PORTAGE_OVERRIDE_EPREFIX=""
PORTAGE_PYM_PATH="/usr/lib64/portage/pym"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_RSYNC_RETRIES="-1"
PORTAGE_SYNC_STALE="30"
PORTAGE_TMPDIR="/var/tmp"
PORTAGE_VERBOSE="1"
PORTAGE_WORKDIR_MODE="0700"
PORTAGE_XATTR_EXCLUDE="security.*"
PORTDIR="/home/ssuominen/gentoo-x86"
PORTDIR_OVERLAY="/usr/local/portage"
PORT_LOGDIR="/var/log/portage"
PORT_LOGDIR_CLEAN="find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +7 -delete"
PRELINK_PATH_MASK="/usr/lib64/libfreebl3.so:/usr/lib64/libnssdbm3.so:/usr/lib64/libsoftokn3.so"
PROFILE_ONLY_VARIABLES="ARCH ELIBC IUSE_IMPLICIT KERNEL USERLAND USE_EXPAND_IMPLICIT USE_EXPAND_UNPREFIXED USE_EXPAND_VALUES_ARCH USE_EXPAND_VALUES_ELIBC USE_EXPAND_VALUES_KERNEL USE_EXPAND_VALUES_USERLAND"
PWD="/home/ssuominen"
PYTHONDONTWRITEBYTECODE="1"
PYTHON_SINGLE_TARGET="python2_7"
PYTHON_TARGETS="python2_7 python3_2"
QT_GRAPHICSSYSTEM="raster"
QT_PLUGIN_PATH="/usr/lib64/kde4/plugins"
RESUMECOMMAND="wget -c -t 3 -T 60 --passive-ftp -O "${DISTDIR}/${FILE}" "${URI}""
RESUMECOMMAND_RSYNC="rsync -avP "${URI}" "${DISTDIR}/${FILE}""
RESUMECOMMAND_SSH="bash -c "x=\${2#ssh://} ; host=\${x%%/*} ; port=\${host##*:} ; host=\${host%:*} ; [[ \${host} = \${port} ]] && port=22 ; exec rsync --rsh=\"ssh -p\${port}\" -avP \"\${host}:/\${x#*/}\" \"\$1\"" rsync "${DISTDIR}/${FILE}" "${URI}""
ROOT="/"
ROOTPATH="/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.8.0"
RPMDIR="/usr/portage/rpm"
RUBYOPT="-rauto_gem"
RUBY_TARGETS="ruby18 ruby19"
SESSION_MANAGER="local/null:@/tmp/.ICE-unix/1213,unix/null:/tmp/.ICE-unix/1213"
SHELL="/bin/bash"
SHLVL="4"
SSH_AGENT_PID="1087"
SSH_AUTH_SOCK="/tmp/ssh-zRzIazJc1mtk/agent.1086"
SYMLINK_LIB="yes"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
TERM="xterm"
UNINSTALL_IGNORE="/lib/modules/*"
USE_ORDER="env:pkg:conf:defaults:pkginternal:repo:env.d"
VIDEO_CARDS="nvidia"
WINDOWID="56623108"
WINDOWPATH="7"
XAUTHORITY="/home/ssuominen/.Xauthority"
XDG_CONFIG_DIRS="/etc/xdg:/etc/xdg"
XDG_DATA_DIRS="/usr/local/share:/usr/share:/usr/share"
XDG_MENU_PREFIX="xfce-"
XDG_SESSION_COOKIE="e764aa8fe16a70438c8999b6502d4bc7-1367653293.340903-2072325035"
XFCE4_SESSION_WITH_CK="1"
XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
_="/usr/bin/emerge"
Comment 1 Samuli Suominen (RETIRED) gentoo-dev 2013-05-08 05:22:49 UTC
syslog-ng-3.4.1 src_prepare():

>>> Emerging (1 of 2) app-admin/syslog-ng-3.4.1
 * Fetching files in the background. To view fetch progress, run
 * `tail -f /var/log/emerge-fetch.log` in another terminal.
 * syslog-ng_3.4.1.tar.gz SHA256 SHA512 WHIRLPOOL size ;-) ...                                                                 [ ok ]
>>> Unpacking source...
>>> Unpacking syslog-ng_3.4.1.tar.gz to /var/tmp/portage/app-admin/syslog-ng-3.4.1/work
>>> Source unpacked in /var/tmp/portage/app-admin/syslog-ng-3.4.1/work
>>> Preparing source in /var/tmp/portage/app-admin/syslog-ng-3.4.1/work/syslog-ng-3.4.1 ...
 * Applying syslog-ng-3.4.1-rollup.patch ...                                                                                   [ ok ]
 * Running eautoreconf in '/var/tmp/portage/app-admin/syslog-ng-3.4.1/work/syslog-ng-3.4.1' ...
 * Running eautoreconf in '/var/tmp/portage/app-admin/syslog-ng-3.4.1/work/syslog-ng-3.4.1/modules/afmongodb/libmongo-client' ...
 * Running eautoreconf in '/var/tmp/portage/app-admin/syslog-ng-3.4.1/work/syslog-ng-3.4.1/lib/ivykis' ...
 * Running eautoreconf in '/var/tmp/portage/app-admin/syslog-ng-3.4.1/work/syslog-ng-3.4.1/modules/afamqp/rabbitmq-c' ...
 * Running libtoolize --install --copy --force --automake ...
Traceback (most recent call last):
  File "/usr/lib64/portage/pym/portage/locks.py", line 103, in lockfile                                                        [ ok ]
 * Running aclocal -I m4 --install ...
    myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR, 0o660)
  File "/usr/lib64/portage/pym/portage/__init__.py", line 246, in __call__
    rval = self._func(*wrapped_args, **wrapped_kwargs)
OSError: [Errno 13] Permission denied: '/var/tmp/portage/app-admin/syslog-ng-3.4.1/.ipc_lock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/portage/bin/ebuild-ipc.py", line 228, in <module>
    sys.exit(ebuild_ipc_main(sys.argv[1:]))
  File "/usr/lib64/portage/bin/ebuild-ipc.py", line 225, in ebuild_ipc_main
    return ebuild_ipc.communicate(args)
  File "/usr/lib64/portage/bin/ebuild-ipc.py", line 82, in communicate
    lock_obj = portage.locks.lockfile(self.ipc_lock_file, unlinkfile=True)
  File "/usr/lib64/portage/pym/portage/locks.py", line 231, in lockfile
    waiting_msg=waiting_msg, flags=flags)
  File "/usr/lib64/portage/pym/portage/locks.py", line 109, in lockfile
    raise PermissionDenied(func_call)
portage.exception.PermissionDenied: open('/var/tmp/portage/app-admin/syslog-ng-3.4.1/.ipc_lock')
 * Running libtoolize --install --copy --force --automake ...
 * Running libtoolize --install --copy --force --automake ...
 * Running libtoolize --install --copy --force --automake ...                                                                  [ ok ]
 * Running aclocal ...                                                                                                         [ ok ]
 * Running aclocal -I m4 --install ...                                                                                         [ ok ]
 * Running aclocal -I m4 ...                                                                                                   [ ok ]
 * Running autoconf ...                                                                                                        [ ok ]
 * Running autoheader ...                                                                                                      [ ok ]
 * Running automake --add-missing --copy --foreign ...                                                                         [ ok ]
 * Running autoconf ...
 * Running autoconf ...
 * Running autoconf ...                                                                                                        [ ok ]
 * Running autoheader ...                                                                                                      [ ok ]
 * Running autoheader ...                                                                                                      [ ok ]
 * Running autoheader ...                                                                                                      [ ok ]
 * Running automake --add-missing --copy --foreign ...                                                                         [ ok ]
 * Running automake --add-missing --copy --foreign ...                                                                         [ ok ]
 * Running automake --add-missing --copy --foreign ...                                                                         [ ok ]
 * Running elibtoolize in: syslog-ng-3.4.1/
 *   Applying portage/1.2.0 patch ...
 *   Applying sed/1.5.6 patch ...
 *   Applying as-needed/2.4.2 patch ...
 *   Applying target-nm/2.4.2 patch ...
 * Running elibtoolize in: syslog-ng-3.4.1/modules/afamqp/rabbitmq-c/
 *   Applying portage/1.2.0 patch ...
 *   Applying sed/1.5.6 patch ...
 *   Applying as-needed/2.4.2 patch ...
 *   Applying target-nm/2.4.2 patch ...
 * Running elibtoolize in: syslog-ng-3.4.1/modules/afmongodb/libmongo-client/
 *   Applying portage/1.2.0 patch ...
 *   Applying sed/1.5.6 patch ...
 *   Applying as-needed/2.4.2 patch ...
 *   Applying target-nm/2.4.2 patch ...
 * Running elibtoolize in: syslog-ng-3.4.1/lib/ivykis/
 *   Applying portage/1.2.0 patch ...
 *   Applying sed/1.5.6 patch ...
 *   Applying as-needed/2.4.2 patch ...
 *   Applying target-nm/2.4.2 patch ...
>>> Source prepared.
Comment 2 Zac Medico gentoo-dev 2013-05-08 07:04:54 UTC
This is strange. What permissions do you have on '/var/tmp/portage/app-admin/syslog-ng-3.4.1/.ipc_lock'?
Comment 3 Samuli Suominen (RETIRED) gentoo-dev 2013-05-08 07:30:52 UTC
(In reply to comment #2)
> This is strange. What permissions do you have on
> '/var/tmp/portage/app-admin/syslog-ng-3.4.1/.ipc_lock'?

Now I can't reproduce this anymore and of course I didn't have anything like 'keepwork' in place so it's impossible for me to get that information.

If this happens again, I'll try to get more data

> myfd = os.open(lockfilename, os.O_CREAT|os.O_RDWR, 0o660)

hmm. 0o660?
Comment 4 SpanKY gentoo-dev 2021-11-03 05:44:31 UTC
we've been hitting this for a long time in CrOS (at least since 2018).  it does seem to be a rare race condition, but when we're constantly building thousands of packages, this doesn't get so rare :).

the issue seems to be that emerge, when running as root with lots of parallel jobs, will grab this ipc_lock that other non-root processes also grab randomly.  but since they both grab & release it quickly, you have to get "lucky" for the race to fail.

basically it looks like:
* [non-root] bin/ebuild-ipc.py:EbuildIpc.communicate sees the lock is free
* [root] lib/_emerge/EbuildIpcDaemon.py:EbuildIpcDaemon._input_handler grabs the lock as 0:0
* [non-root] bin/ebuild-ipc.py:EbuildIpc.communicate tries to grab the lock, but fails with EACCES
* everything blows up

we managed to capture a (hand trace) of the filesystem state here:
https://issuetracker.google.com/issues/187785642#comment43

and not quite as good of a capture of the failure, but includes the process information:
* we see that `emerge` (root) owns the lock
* it's the `ebuild` (non-root) trying to grab it and sees that emerge holds it
https://issuetracker.google.com/issues/187785642#comment51

i'm not familiar with what resources these locks are protecting, so i can't suggest a quick fix.  it feels like having EbuildIpcDaemon just use a diff filename is probably the wrong answer.
Comment 5 Zac Medico gentoo-dev 2021-11-03 20:16:54 UTC
(In reply to SpanKY from comment #4)
> i'm not familiar with what resources these locks are protecting, so i can't
> suggest a quick fix.  it feels like having EbuildIpcDaemon just use a diff
> filename is probably the wrong answer.

A likely trigger is the lock related to bug 401919 inside lib/_emerge/EbuildIpcDaemon.py, since this code runs as root:

> else:  # EIO/POLLHUP
>     # This can be triggered due to a race condition which happens when
>     # the previous _reopen_input() call occurs before the writer has
>     # closed the pipe (see bug #401919). It's not safe to re-open
>     # without a lock here, since it's possible that another writer will
>     # write something to the pipe just before we close it, and in that
>     # case the write will be lost. Therefore, try for a non-blocking
>     # lock, and only re-open the pipe if the lock is acquired.
>     lock_filename = os.path.join(os.path.dirname(self.input_fifo), ".ipc_lock")
>     try:
>         lock_obj = lockfile(lock_filename, unlinkfile=True, flags=os.O_NONBLOCK)
>     except TryAgain:
>         # We'll try again when another IO_HUP event arrives.
>         pass
>     else:
>         try:
>             self._reopen_input()
>         finally:
>             unlockfile(lock_obj)
Comment 6 Zac Medico gentoo-dev 2021-11-06 06:24:26 UTC
I've realized that there's actually a permission race in the lockfile creation,  which we can solve by doing a chmod g+s on the parent directory, and umask 0002 during creation of the lockfile.
Comment 7 Larry the Git Cow gentoo-dev 2021-11-10 23:18:17 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=704bcd1581e49432f363f0eda648d58411775d7f

commit 704bcd1581e49432f363f0eda648d58411775d7f
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2021-11-07 04:19:58 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2021-11-10 23:10:53 +0000

    EbuildIpcDaemon: fix lock permission race
    
    Move ipc files to a .ipc subdirectory, with a setgid bit to
    prevent a lockfile group permission race. The lockfile function
    uses an appropriate open call with mode argument so that the
    lockfile is created atomically with both group ownership and
    group write bit.
    
    Bug: https://bugs.gentoo.org/468990
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 bin/ebuild-ipc.py                                | 6 +++---
 bin/phase-functions.sh                           | 4 ++--
 lib/_emerge/AbstractEbuildProcess.py             | 4 ++--
 lib/_emerge/EbuildIpcDaemon.py                   | 2 +-
 lib/portage/package/ebuild/prepare_build_dirs.py | 9 +++++++++
 lib/portage/tests/ebuild/test_doebuild_spawn.py  | 1 +
 lib/portage/tests/ebuild/test_ipc_daemon.py      | 6 +++---
 7 files changed, 21 insertions(+), 11 deletions(-)
Comment 8 Mike Gilbert gentoo-dev 2022-04-11 20:26:09 UTC
Released in portage-3.0.29.