From a644c10e180ce8af789ea3e4e4892dcf078e97e2 Mon Sep 17 00:00:00 2001 From: Shannon Wynter Date: Thu, 19 May 2016 15:18:05 +1000 Subject: [PATCH] Clean up processes when the websocket exits --- main.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 60f4be8..2459935 100644 --- a/main.go +++ b/main.go @@ -46,10 +46,14 @@ func handleWebsocket(w http.ResponseWriter, r *http.Request) { conn.WriteMessage(websocket.TextMessage, []byte(err.Error())) return } - defer tty.Close() + defer func() { + cmd.Process.Kill() + cmd.Process.Wait() + tty.Close() + conn.Close() + }() go func() { - defer conn.Close() for { buf := make([]byte, 1024) read, err := tty.Read(buf) @@ -66,7 +70,6 @@ func handleWebsocket(w http.ResponseWriter, r *http.Request) { messageType, reader, err := conn.NextReader() if err != nil { l.WithError(err).Error("Unable to grab next reader") - conn.WriteMessage(websocket.TextMessage, []byte(err.Error())) return }