From 66426acfbb232d35804be672dda6455a2ab007cd Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Wed, 13 Aug 2025 15:04:18 -0400 Subject: [PATCH] CLI: Defer tty reset immediately (#488) We were defer closing the IO for run/exec/start fairly late in the container run cycle which had the downside of that if the container run failed your tty would be stuck in raw mode. This change just moves the closing (return tty to origin state) to directly after we create the IO. --- Package.resolved | 4 ++-- Sources/CLI/Application.swift | 3 --- Sources/CLI/Container/ContainerExec.swift | 3 +++ Sources/CLI/Container/ContainerStart.swift | 6 +++--- Sources/CLI/RunCommand.swift | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Package.resolved b/Package.resolved index 90b1a5b0..7a8431ec 100644 --- a/Package.resolved +++ b/Package.resolved @@ -240,8 +240,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax.git", "state" : { - "revision" : "fd6373fad9cf3b3bc4e3c06d92f0cfd60007fa8e", - "version" : "602.0.0-prerelease-2025-06-26" + "revision" : "21b3b45635decd1a0b89968f81b6d9a93128f773", + "version" : "602.0.0-prerelease-2025-08-11" } }, { diff --git a/Sources/CLI/Application.swift b/Sources/CLI/Application.swift index b588e193..66730370 100644 --- a/Sources/CLI/Application.swift +++ b/Sources/CLI/Application.swift @@ -190,9 +190,6 @@ struct Application: AsyncParsableCommand { } try await process.start() - defer { - try? io.close() - } try io.closeAfterStart() if let current = io.console { diff --git a/Sources/CLI/Container/ContainerExec.swift b/Sources/CLI/Container/ContainerExec.swift index 3bee2c15..dc4a92ae 100644 --- a/Sources/CLI/Container/ContainerExec.swift +++ b/Sources/CLI/Container/ContainerExec.swift @@ -70,6 +70,9 @@ extension Application { do { let io = try ProcessIO.create(tty: tty, interactive: stdin, detach: false) + defer { + try? io.close() + } if !self.processFlags.tty { var handler = SignalThreshold(threshold: 3, signals: [SIGINT, SIGTERM]) diff --git a/Sources/CLI/Container/ContainerStart.swift b/Sources/CLI/Container/ContainerStart.swift index 45d54eac..4f8a86cf 100644 --- a/Sources/CLI/Container/ContainerStart.swift +++ b/Sources/CLI/Container/ContainerStart.swift @@ -58,15 +58,15 @@ extension Application { interactive: self.interactive, detach: detach ) + defer { + try? io.close() + } let process = try await container.bootstrap(stdio: io.stdio) progress.finish() if detach { try await process.start() - defer { - try? io.close() - } try io.closeAfterStart() print(self.containerID) return diff --git a/Sources/CLI/RunCommand.swift b/Sources/CLI/RunCommand.swift index 82b9b956..ef116b28 100644 --- a/Sources/CLI/RunCommand.swift +++ b/Sources/CLI/RunCommand.swift @@ -116,6 +116,9 @@ extension Application { interactive: self.processFlags.interactive, detach: detach ) + defer { + try? io.close() + } let process = try await container.bootstrap(stdio: io.stdio) progress.finish() @@ -138,9 +141,6 @@ extension Application { if detach { try await process.start() - defer { - try? io.close() - } try io.closeAfterStart() print(id) return