SwiftPM hangs at "Planning build" on every incremental build (Swift 6.2, Linux)

Hi everyone,

I'm experiencing a critical issue with Swift 6.2 on Linux where SwiftPM hangs indefinitely during any incremental build.

Environment

  • Swift: 6.2 (swift-6.2-RELEASE)
  • OS: Ubuntu 24.04.3 LTS
  • Kernel: Linux 6.8.0-60-generic x86_64

The Problem

After the initial clean build succeeds, any subsequent swift build hangs forever at the "Planning build" phase. This happens even on a
minimal project created with swift package init.

# First build - works fine
swift build
# Output: Build complete! (5-10 seconds)

# Second build - hangs indefinitely
swift build
# Hangs at "Planning build", never completes

What I've Tried

:cross_mark: swift build -Xswiftc -whole-module-optimization - still hangs
:cross_mark: swift build -c release - still hangs
:cross_mark: swift build --verbose - shows "Planning build" then hangs
:cross_mark: Different targets/test commands - all hang

:white_check_mark: Only workaround: Full reset before each build

swift package purge-cache && swift package reset && swift build

This adds 30-40 seconds to every build, making development impractical.

Impact

This completely breaks the development workflow on Linux. Incremental builds that should take 1-5 seconds now require 30-60 seconds for a full
rebuild every time.

Questions

1. Is this a known regression in Swift 6.2 on Linux?
2. Are there any environment variables or flags to fix incremental compilation?
3. Has anyone else experienced this?

I've filed a GitHub issue with full reproduction steps: SwiftPM hangs indefinitely at "Planning build" on incremental builds since Swift 6.1 in some Ubuntu KVM environments · Issue #9441 · swiftlang/swift-package-manager · GitHub

Any help or insights would be greatly appreciated!

UPDATE (December 6, 2025):

We've identified this as a regression between Swift 6.0 and 6.1. The issue does not reproduce on Swift 6.0 or 5.10 – incremental builds work correctly on these versions.

Detailed regression analysis with test results for 5 Swift versions (5.10, 6.0, 6.1, 6.2, 6.2.1) has been posted to the GitHub issue: SwiftPM hangs indefinitely at "Planning build" on incremental builds (Swift 6.2, Linux) · Issue #9441 · swiftlang/swift-package-manager · GitHub

For now, we're using Swift 6.0 as a workaround until this gets fixed upstream.

I find it weird that you run into this because I’ve used Swift 6.1 and 6.2 on Ubuntu 24.04 on multiple different machines and never seen this problem. I’ve also done multiple builds on aarch64 and still haven’t seen this.

If you ran the same test on an entirely different machine, do you have the same issue?

@xtremekforever

If you ran the same test on an entirely different machine, do you have the same issue?

Yes! I've now tested on two different machines:

  1. Desktop (bare metal Ubuntu 24.04.1, kernel 6.8.0-60)
  2. VPS (Ubuntu 24.04.3, kernel 6.8.0-60, hosted VM)

Both reproduce the hang consistently.

However, here's the interesting finding:

Virtualization layer matters:

  • :white_check_mark: KVM (both machines above) → HANGS
  • :cross_mark: macOS Docker Desktop (VM via Apple Virtualization.framework) → WORKS

I ran the exact same Docker test (swift:6.2.1 container) on macOS and incremental builds complete successfully in 0.17s.

strace analysis (from Linux/KVM environment) shows the process enters a livelock:

Process 285 (swift-build):
epoll_wait() → wakes up every 1 second via timerfd
checks for events → none available
goes back to epoll_wait()
[repeats indefinitely]

No network calls to GitHub detected — this rules out the DNS/connectivity hypothesis.

Current hypothesis:
The issue appears specific to KVM-based Linux environments, possibly related to:

  • epoll/timerfd behavior in KVM
  • file locking semantics
  • scheduler differences

I'm reaching out to my hosting provider to investigate KVM-specific configurations.

Would anyone from the Swift team be interested in the full strace logs or system details?

So that’s confusing because you say both machines above are KVM, but then your “1. Desktop (bare metal Ubuntu 24.04.1, kernel 6.8.0-60)” machine would not be “bare metal” if it’s a KVM…

I've been hitting a similar SwiftPM hang on Arch Linux in only one of my projects (I work on a lot of them these days) when incrementally running (before "Planning build"). Even no changes at all makes it hang at least 20+ seconds between runs, not indefinitely. I thought it was a kernel issue due to it showing up after upgrading it recently (for like the past month or two).

Executing journalctl --since=today shows that systemd spams Looping too fast. Throttling execution a little. when I try running the affected Swift project, and the swiftly run swift run command is dominating the CPU.

I don't know if it helps but strace -T swiftly run swift run shows the hang is due to a suspend for the exact time it takes before "Planning build".

strace affected project
Run 1:
rt_sigsuspend([], 8)                    = ? ERESTARTNOHAND (To be restarted if no handler) <44.275390>
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=248923, si_uid=1000, si_status=0, si_utime=1481 /* 14.81 s */, si_stime=171 /* 1.71 s */} ---

Run 2:
rt_sigsuspend([], 8)                    = ? ERESTARTNOHAND (To be restarted if no handler) <20.156726>
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=253608, si_uid=1000, si_status=0, si_utime=1480 /* 14.80 s */, si_stime=173 /* 1.73 s */} ---

For context, here is the same command (on the same machine using the same 6.2 toolchain [not a VM or used in a container; x86_64]) executed on a Swift project that doesn't suffer from the hang:

strace unaffected project
Run 1:
rt_sigsuspend([], 8)                    = ? ERESTARTNOHAND (To be restarted if no handler) <2.939136>
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=255104, si_uid=1000, si_status=0, si_utime=24 /* 0.24 s */, si_stime=21 /* 0.21 s */} ---

Run 2:
rt_sigsuspend([], 8)                    = ? ERESTARTNOHAND (To be restarted if no handler) <2.056017>
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=255250, si_uid=1000, si_status=0, si_utime=24 /* 0.24 s */, si_stime=18 /* 0.18 s */} ---

I also think it is due to some sort of file locking (as mentioned on your github issue), but whether Swift/SwiftPM or the Kernel is to blame I do not know.


Worth noting: also hangs using latest toochain via Swiftly (6.2.1).

1 Like

Apologies for the confusion about "bare metal" - this is indeed a KVM VDS environment. Good catch @xtremekforever.

Testing progress:

  • Tested on kernel 6.11.0-29 (upgraded from 6.8) - issue persists
  • Applied various tuning parameters (inotify, scheduler) - no improvement
  • Reproduced on minimal "Hello World" SPM project - so it's NOT project-specific in my case

Same epoll_wait/timerfd_settime loop pattern in strace.

Current workaround: Downgraded to Swift 6.0 where incremental builds work fine.

Still investigating with hosting provider whether this is KVM timer/clock-specific. Will update if we find the root cause.

Interesting that @RandomHashTags sees it on Arch - suggests it might not be Ubuntu-specific either.

1 Like

:white_check_mark: Fixed in Development Snapshots

The hang is resolved in Swift development snapshots from 2025-12-15 onwards.

To fix: Use Swift 6.3-dev snapshot (or wait for Swift 6.3 release)

Download: Install Swift | Swift.org

Verified working on Ubuntu 24.04 KVM - incremental builds work normally now.

See GitHub Issue #9441 for details and PR #9493 for the fix.

1 Like