Skip to content

Replace Thread.sleep with async sleep in DaemonLauncher.killExistingDaemon #57

@2witstudios

Description

@2witstudios

Context

DaemonLifecycle.swiftDaemonLauncher.killExistingDaemon() (lines 78-105) uses Thread.sleep(forTimeInterval: 0.1) in a polling loop (up to 20 iterations = 2 seconds) to wait for a daemon process to die after SIGTERM.

Problem

Thread.sleep blocks the actor's executor thread, preventing any other work from running on the DaemonLauncher actor during that time. Since killExistingDaemon is called from async methods (ensureDaemon, restartDaemon), it should use cooperative async sleeping.

Proposal

Make killExistingDaemon() async and replace Thread.sleep with try await Task.sleep:

private func killExistingDaemon() async {
    // ...
    kill(pid, SIGTERM)
    
    for _ in 0..<20 {
        try? await Task.sleep(nanoseconds: 100_000_000)
        if kill(pid, 0) != 0 { break }
    }
    // ...
}

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions