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

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).