SPM may crash randomly with debug-build libdispatch #8197
Description
Is it reproducible with SwiftPM command-line tools: swift build
, swift test
, swift package
etc?
- Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands,
swift build
,swift test
,swift package
etc.
Description
In execute(path:args)
, it closes all file descriptors in a loop, this includes file descriptors owned by libdispatch
, which triggers an assertion and crash the process with the message: "BUG IN CLIENT OF LIBDISPATCH: Do not close random Unix descriptors"
This causes failure in building the toolchain with debuggable libdispatch on systems using kqueue with option DISPATCH_USE_MGR_THREAD
.
Some details of what's happening:
-
_dispatch_kq_create
creates a kqueue file descriptor and setdispatch_mgr_q.do_ctxt
to it. -
execute(path:args)
closes all file descriptors, in a loop, which includes the kqueue created in (1), now this function enters a race withlibdispatch
’s draining code paths. -
If
_dispatch_kq_poll
wins,kevent(2)
will fail becausekqfd
is no longer a valid file descriptor, this causeserrno
set toEBADF
, and if debug is enabled on libdispatch, the assertion crash the entire process.
Expected behavior
swift package manager should not crash even with debug build of libdispatch
Actual behavior
swift package manager sometimes crashes
Steps to reproduce
No response
Swift Package Manager version/commit hash
No response
Swift & OS version (output of swift --version ; uname -a
)
Swift version 6.1-dev (LLVM 42f3e8ef873e24d, Swift 567379be804a8c6)
Target: x86_64-unknown-freebsd14.1
FreeBSD 14.1-RELEASE-p6 FreeBSD 14.1-RELEASE-p6 releng/14.1-n267727-74b6c983723c GENERIC amd64