Does Concurrency Work in Docker?

my docker file is

# Use the official Swift image from the Docker Hub
FROM swift:5.10

# Set a working directory inside the container

# Copy the Package.swift and Sources directory into the container at /app
COPY Package.swift ./
COPY Sources ./Sources

# Build the Swift package
RUN swift build

# Run the executable produced by the build
CMD ["swift", "run", "SomeFile"]

and my code contains

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#if canImport(_Concurrency)
import _Concurrency


let (data, _) = try await request)

but got

2.409 /app/Sources/MyFile.swift:34:57: error: value of type 'URLSession' has no member 'data'
2.409 let (data, _) = try await request)
2.409 ~~~~~~~~~~~~~~~~~ ^~~~

do you know how to fix it?

Corelibs foundation is a different implementation on Linux currently, and it has many missing APIs. So what you’re experiencing is a different library on Linux not having the api you expect.

There’s an active process to resolve this weird situation by implementing foundation in swift which is over here: GitHub - apple/swift-foundation: The Foundation project and then both platforms will be using the exact same implementation, resolving the issue you’ve hit.

In practice for http clients though I’d recommend using the async http client library anyway: GitHub - swift-server/async-http-client: HTTP client library built on SwiftNIO as it’s more geared towards the server ecosystem.

Hope this helps


thanks a lot it does help!

1 Like

Unless you happen to use something of that stable and solid „deprecated“ API that‘s not going to be implemented in the new one

Actually, just today Jonathan submitted a PR Add async URLSession methods by jrflat · Pull Request #4970 · apple/swift-corelibs-foundation · GitHub implementing the missing methods in the corelibs URLSession :slight_smile:

So while the medium and long term story remains about GitHub - apple/swift-foundation: The Foundation project this specific issue would also be fixed in corelibs :slight_smile:


That‘s very good news. There are so many important pull requests lingering, a bit of traction would suit that project very well.

1 Like