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

I just wanted to add that I’m encountering some strange network issues when running web SPA, on the iOS simulator for versions 18.4 and 18.5 , but not on 17.0! The network failures happen randomly and i can totally reproduce them after some tries.

When inspecting via Safari’s Web Inspector on the simulator, the failing requests show the following error:

“Failed to load resource: The network connection was lost.”

In the network panel, these failed requests show completely empty values for status, protocol, connection ID, IP, and transferred size. They also fail very quickly and never even show up in the server logs, which makes them really hard to diagnose.

Interestingly, this behavior seems to be specific to Safari on iOS and macOS. They work without any issues on Chrome or Android, no failures at all.

I suspect this might be related to how newer iOS versions handle network connections, particularly keep-alive connections. It’s possible that Safari is attempting to reuse a connection that the server has already closed, and doesn’t know how to recover gracefully from that.

Just to emphasize: • This happens in Safari 18.4 and 18.5. • Safari 17.0 runs the exact same app flawlessly. • I haven’t tested any versions between 17.0 and 18.4 yet.

Not sure if related to this URLSession but the error is very similar...

FWIW, I'm seeing something similar to the original problem, occurring when I try to run code inside the new #Playground structure in Xcode 26 (beta 7). Any attempt to execute an URLRequest ends in "A server with the specified hostname could not be found." I've tried a number of things mentioned in this discussion, such as using "URLSessionConfiguration.ephemeral" and setting "tlsMaximumSupportedProtocolVersion = .TLSv12". Is this simply unsupported behavior inside of a #Playground, or am I missing something?

URLSession is broken in iOS 18.4 RC Simulator
 
 
Q