swiftlang / swift-sdk-generator

Generate Swift SDKs for cross-compilation
Apache License 2.0
182 stars 15 forks source link

ProcessExecutor: add teardown sequences #100

Closed weissi closed 7 months ago

weissi commented 7 months ago

This allows to write

        let p = ProcessExecutor(
            executable: "/usr/bin/swift",
            [ "build", "-c", "release" ],
            teardownSequence: [
                .sendSignal(SIGINT, allowedTimeToExitNS: 100_000_000), // SIGINT, then 100s
                .sendSignal(SIGTERM, allowedTimeToExitNS: 1_000_000_000), // SIGTERM, then 1s
                // and always SIGKILL if nothing worked
            ]
        )

which allows the process (swift build in this case) to clean up its child processes.

MaxDesiatov commented 7 months ago

@swift-ci test

MaxDesiatov commented 7 months ago

@swift-ci test

kateinoigakukun commented 7 months ago

Hmm, it seems the teardown sequence somehow does not wait for allowedTimeNS Never mind, the number in the PR description was wrong, 1sec should be 100_000_000_000

2024-04-05T22:46:26+0900 debug swift-async-process : arguments=["-c", "cat \"/var/folders/k2/q6yzck31253_q1j4kxkzq5jh0000gn/T/swift-sdk-generator-008142\"/*.pkg/Payload | gunzip -cd | (cd \"/var/folders/k2/q6yzck31253_q1j4kxkzq5jh0000gn/T/swift-sdk-generator-42E0B0\" && cpio -i)"] executable=/bin/sh pid=66892 [AsyncProcess] running command
^C2024-04-05T22:46:31+0900 debug swift-async-process : pid=66892 [AsyncProcess] we got cancelled
2024-04-05T22:46:31+0900 trace swift-async-process : pid=66892 step=sendSignal(2, allowedTimeNS: 100000000) [AsyncProcess] running teardown sequence
2024-04-05T22:46:31+0900 debug swift-async-process : outcome=processStillAlive pid=66892 step=sendSignal(2, allowedTimeNS: 100000000) [AsyncProcess] teardown sequence step complete
2024-04-05T22:46:31+0900 trace swift-async-process : pid=66892 step=sendSignal(15, allowedTimeNS: 1000000000) [AsyncProcess] running teardown sequence
2024-04-05T22:46:31+0900 debug swift-async-process : arguments=["-c", "cat \"/var/folders/k2/q6yzck31253_q1j4kxkzq5jh0000gn/T/swift-sdk-generator-008142\"/*.pkg/Payload | gunzip -cd | (cd \"/var/folders/k2/q6yzck31253_q1j4kxkzq5jh0000gn/T/swift-sdk-generator-42E0B0\" && cpio -i)"] executable=/bin/sh pid=66892 termination-reason=signal termination-status=15 [AsyncProcess] finished running command
2024-04-05T22:46:31+0900 debug swift-async-process : outcome=processHasExited pid=66892 step=sendSignal(15, allowedTimeNS: 1000000000) [AsyncProcess] teardown sequence step complete
SwiftSDKGenerator/Shell.swift:90: Fatal error
zsh: trace trap  swift run swift-sdk-generator make-linux-sdk
weissi commented 7 months ago

~Hmm, it seems the teardown sequence somehow does not wait for allowedTimeNS~ Never mind, the number in the PR description was wrong, 1sec should be 100_000_000_000

that'd be 100s. 1s is 1_000_000_000

kateinoigakukun commented 7 months ago

Ah, yes, 100s is 100_000_000_000ns