Skip to content

Commit a19ce86

Browse files
authored
Swallow SIGINT while running kubectl (#380)
1 parent c34a819 commit a19ce86

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/FSLibrary/StellarSupercluster.fs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,20 @@ let ConnectToCluster (cfgFile: string) (nsOpt: string option) : (Kubernetes * st
6262
with :? ComponentModel.Win32Exception -> false
6363

6464
if started then
65-
if proc.WaitForExit(TimeSpan(0, 1, 0)) then
66-
if proc.ExitCode = 0 then RanSuccess else RanWithError proc.ExitCode
67-
else
68-
proc.Kill()
69-
DidNotComplete(proc.WaitForExit(TimeSpan(0, 1, 0)))
65+
// Swallow Ctrl+C in the parent while kubectl is running, so the
66+
// SIGINT delivered to the foreground process group only stops
67+
// kubectl and lets us decide what to do next.
68+
let cancelHandler = ConsoleCancelEventHandler(fun _ e -> e.Cancel <- true)
69+
Console.CancelKeyPress.AddHandler cancelHandler
70+
71+
try
72+
if proc.WaitForExit(TimeSpan(0, 1, 0)) then
73+
if proc.ExitCode = 0 then RanSuccess else RanWithError proc.ExitCode
74+
else
75+
proc.Kill()
76+
DidNotComplete(proc.WaitForExit(TimeSpan(0, 1, 0)))
77+
finally
78+
Console.CancelKeyPress.RemoveHandler cancelHandler
7079
else
7180
DidNotRun)
7281

0 commit comments

Comments
 (0)