swift-server / swift-service-lifecycle

Cleanly startup and shutdown server application, freeing resources in order before exiting.
https://swiftpackageindex.com/swift-server/swift-service-lifecycle/documentation/servicelifecycle
Apache License 2.0
396 stars 38 forks source link

Crash cancelling ServiceGroup.run() in Swift 6 #180

Closed adam-fowler closed 6 months ago

adam-fowler commented 6 months ago

With Swift 6 nightly: swift-6.0-DEVELOPMENT-SNAPSHOT-2024-04-06-a I get a crash when cancelling ServiceGroup.run

struct TestService: Service {
    func run() async throws {
        try await gracefulShutdown()
    }
}
await withThrowingTaskGroup(of: Void.self) { group in
    let serviceGroup = ServiceGroup(
        configuration: .init(
            services: [TestService()],
            gracefulShutdownSignals: [.sigterm, .sigint],
            logger: Logger(label: "JobQueueService")
        )
    )
    group.addTask {
        try await serviceGroup.run()
    }
    group.cancelAll()
}

It crashes on this line with a EXC_BAD_ACCESS https://github.com/swift-server/swift-service-lifecycle/blob/f5780d95bdf3f740f14decb6c8c823815c883451/Sources/ServiceLifecycle/ServiceGroup.swift#L498

Swift --version output

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
FranzBusch commented 6 months ago

@adam-fowler are you able to reproduce this still?

adam-fowler commented 6 months ago

Ok it seems to have resolved itself