macos: fail fast when SSH tunnel exits
This commit is contained in:
@@ -267,9 +267,17 @@ final class ControlChannel: ObservableObject {
|
|||||||
}
|
}
|
||||||
proc.arguments = args
|
proc.arguments = args
|
||||||
proc.standardInput = nil
|
proc.standardInput = nil
|
||||||
proc.standardOutput = Pipe()
|
let outPipe = Pipe()
|
||||||
proc.standardError = Pipe()
|
let errPipe = Pipe()
|
||||||
|
proc.standardOutput = outPipe
|
||||||
|
proc.standardError = errPipe
|
||||||
try proc.run()
|
try proc.run()
|
||||||
|
// Give ssh a brief moment; if it exits immediately, surface the error.
|
||||||
|
try? Task.sleep(nanoseconds: 200_000_000) // 200ms
|
||||||
|
if !proc.isRunning {
|
||||||
|
let err = String(data: errPipe.fileHandleForReading.readDataToEndOfFile(), encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
throw ControlChannelError.sshFailed(err ?? "ssh exited")
|
||||||
|
}
|
||||||
self.sshProcess = proc
|
self.sshProcess = proc
|
||||||
return localPort
|
return localPort
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user