Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM may crash randomly with debug-build libdispatch #8197

Open
1 task done
michael-yuji opened this issue Jan 6, 2025 · 0 comments
Open
1 task done

SPM may crash randomly with debug-build libdispatch #8197

michael-yuji opened this issue Jan 6, 2025 · 0 comments
Labels

Comments

@michael-yuji
Copy link
Contributor

michael-yuji commented Jan 6, 2025

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:

  1. _dispatch_kq_create creates a kqueue file descriptor and set dispatch_mgr_q.do_ctxt to it.

  2. execute(path:args) closes all file descriptors, in a loop, which includes the kqueue created in (1), now this function enters a race with libdispatch’s draining code paths.

  3. If _dispatch_kq_poll wins, kevent(2) will fail because kqfd is no longer a valid file descriptor, this causes errno set to EBADF, 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

@michael-yuji michael-yuji changed the title SwiftRunCommand.exec(path:args:) causes crash with debug-build libdispatch SPM may crash randomly with debug-build libdispatch Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant