LLDB RPC server crashes when running top-level async code in Playground files

When running top-level async code in Swift Playgrounds, the LLDB RPC server crashes.

For example, when running the following code from Concurrency section of The Swift Programming Language book:

func fetchUserID(from server: String) async -> Int {
    if server == "primary" {
        return 97
    }
    return 501
}

let userIDs = await withTaskGroup(of: Int.self) { group in
    for server in ["primary", "secondary", "development"] {
        group.addTask {
            return await fetchUserID(from: server)
        }
    }

    var results: [Int] = []
    for await result in group {
        results.append(result)
    }
    return results
}

print(userIDs)

Xcode reports that the LLDB RPC server has crashed. The Swift Playground app reports “There was a problem running this playground.” However, in the case of the Swift Playground app, results are populated as expected. For example, the console shows “[97, 501, 501]”. Xcode does not print any results in the console.

Tested with Xcode 26.4 (17E192) and Swift Playground Version 4.7 (2088).

Wrapping the async code in a Task {} resolves the issue. Running this code in a standalone Swift file produces the expected result without an error.

FB22416465

From the analytics report, attached in the feedback report, but in case it helps others identify the same issue in their crashes:

Triggered by Thread: 26  RPC packet thread for client tid 013af238 (20640312)

Exception Type:    EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000000005a8
Exception Codes:   0x0000000000000001, 0x00000000000005a8

Termination Reason:  Namespace SIGNAL, Code 11, Segmentation fault: 11
Terminating Process: exc handler [64943]


VM Region Info: 0x5a8 is not in any region.  Bytes before following region: 4296211032
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      100130000-1003b8000    [ 2592K] r-x/r-x SM=COW  /Applications/Xcode-26.4.0-Release.Candidate.app/Contents/SharedFrameworks/LLDBRPC.framework/Versions/A/Resources/lldb-rpc-server

I think this falls under the category of Just A Bug™. Thanks for filing FB22416465.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

LLDB RPC server crashes when running top-level async code in Playground files
 
 
Q