Skip to content

Commit

Permalink
Clean up processes when the websocket exits
Browse files Browse the repository at this point in the history
  • Loading branch information
swynter-ladbrokes committed May 19, 2016
1 parent f72bb67 commit a644c10
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit a644c10

Please sign in to comment.