URLSession is broken in iOS 18.4 RC Simulator

I'm seeing fully reproducible issues with URLSession on iOS 18.4 RC Simulator running from Xcode 16.3 RC. URLSession seems to get into a broken state after a second app run. The following sample succeeds in fetching the JSON on first app run but when the app is closed and ran again it fails with one of these errors:

  • Error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
  • Error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."

I'm wondering if this something related to my OS setup or is this due to internal URLSession changes in iOS 18.4. Already submitted as FB17006003.

Sample code attached below:

import SwiftUI

@main
struct NetworkIssue18_4App: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    @State private var message: String = ""

    var body: some View {
        VStack {
            Text(message)

            Button("Try Again") {
                Task {
                    await fetch()
                }
            }
        }
        .task {
            await fetch()
        }
    }

    private func fetch() async {
        message = "Loading..."
        let url = URL(string: "https://poetrydb.org/title/Ozymandias/lines.json")!
        let session = URLSession.shared
        do {
            let response = try await session.data(from: url)
            print("Response: \(response)")
            message = "Success, data length: \(response.0.count)"
        } catch {
            print("Error: \(error)")
            message = "Error: \(error.localizedDescription)"
        }
    }
}
Answered by jhowlin in 837411022

Good news: Appears to be fixed in Xcode 16.4 beta 1.

I messed up my live coding interview because of this.

I had to share my screen so the interviewer could see what I was doing, so I ran the simulator. only to end up showing them a pathetic developer who cannot make even a single image downloader from server, debugging network request within 1 hour. I hope this would be fixed in Xcode 16.4.

Thanks Apple.

Appears to be fixed now when using the Simulator 16.0 with iOS 18.5. At least I see http/3 working fine now from the iPhone and iPad in the simulator with my app and also with Safari.

Xcode 16.4 (16F6), iOS 18.4 Simulator - issue still exists

Xcode 16.4 (16F6), iOS 18.5 Simulator - issue resolved

Yeah, it's about the runtimes mainly. Let's pretend 18.3 and 18.4 Simulators never existed. 😄

The following warnings are alive and well on Xcode 16.4 (16F6) w/ iOS 18.5 simulator

Can confirm this as well with Xcode 16.4 (16F6) and Simulator 16.0 1042.1

URLSession is broken in iOS 18.4 RC Simulator
 
 
Q