Skip to content

Async Process IO hangs 100% of the time on Linux #5197

Open
@danpalmer

Description

@danpalmer

Summary

I have a wrapper around Process designed to asynchronously run and read stdout/stderr in order to allow for the following API:

let (stdout, stderr) = try await run("/bin/ls", ["."])

Under macOS (15.x) this works, but under Linux, specifically using the swift:6 Docker image, this hangs indefinitely.

Detailed issue

Under some running conditions it's possible to observe the following error:

*** Could not create wakeup socket pair for CFSocket!!!

Additionally, although not my concern it may help debug, the same code crashes with a bad pointer dereference in libswift_Concurrency.so on Swift 5.9.

strace'ing this suggests that the subprocess does indeed run and complete, so indicates an issue with the Swift run loop.

One possibility is that there's a file handle limit preventing the I/O from happening, however ulimit suggests that this container has no limits that would be causing an issue.

Given that the same code works on macOS and does not on Linux, suggests to me a bug in the framework. While I'm conscious that it's very easy to introduce races in code like this (and I have fixed several in this area), a difference in behaviour like this should be impossible, or at least documented and obvious.

Reproduction

I've create a relatively minimal reproduction, with code similar to what's in my project, available here: https://github.com/danpalmer/swift-linux-issue 1.

# Works as expected
$ swift run

# Hangs
$ docker run --rm -v $(pwd):/code -w /code swift:6.0 swift run

To run this you'll need to install a Docker provider on macOS such as OrbStack.

Happy to answer any questions or provide further follow-up. This area is not something I know a lot about – I would consider myself an intermediate Swift developer and a relatively basic Linux user, so it's quite possible that I've missed obvious things that I should go back and try before further investigation occurs.

Footnotes

  1. Please note that this was AI generated, but a) appears to reproduce the issue correctly working as expected on macOS and hanging in the same way on Linux, and b) is highly representative of both the current code I have in my project and an open source library that both exhibit the same issue in the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions