feat: add connection segfault protection

A user recently reported a crash on a failed connection. This handles
these errors more gracefully than the previous system and prints the
errors to the connection prompt.
This commit is contained in:
Sylvia Crowe 2024-03-14 16:19:32 -07:00
parent bb8f5dc660
commit 81294820c8

View File

@ -15,6 +15,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"regexp" "regexp"
"runtime/debug"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -1176,6 +1177,15 @@ func (msh *MShellProc) WaitAndSendPassword(pw string) {
} }
func (msh *MShellProc) RunInstall(autoInstall bool) { func (msh *MShellProc) RunInstall(autoInstall bool) {
defer func() {
if r := recover(); r != nil {
errMsg := fmt.Errorf("this should not happen. if it does, please reach out to us in our discord or open an issue on our github\n\n"+
"error:\n%v\n\nstack trace:\n%s", r, string(debug.Stack()))
log.Printf("fatal error, %s\n", errMsg)
msh.WriteToPtyBuffer("*fatal error, %s\n", errMsg)
msh.setErrorStatus(errMsg)
}
}()
remoteCopy := msh.GetRemoteCopy() remoteCopy := msh.GetRemoteCopy()
if remoteCopy.Archived { if remoteCopy.Archived {
msh.WriteToPtyBuffer("*error: cannot install on archived remote\n") msh.WriteToPtyBuffer("*error: cannot install on archived remote\n")
@ -1550,6 +1560,15 @@ func (msh *MShellProc) createWaveshellSession(clientCtx context.Context, remoteC
} }
func (msh *MShellProc) Launch(interactive bool) { func (msh *MShellProc) Launch(interactive bool) {
defer func() {
if r := recover(); r != nil {
errMsg := fmt.Errorf("this should not happen. if it does, please reach out to us in our discord or open an issue on our github\n\n"+
"error:\n%v\n\nstack trace:\n%s", r, string(debug.Stack()))
log.Printf("fatal error, %s\n", errMsg)
msh.WriteToPtyBuffer("*fatal error, %s\n", errMsg)
msh.setErrorStatus(errMsg)
}
}()
remoteCopy := msh.GetRemoteCopy() remoteCopy := msh.GetRemoteCopy()
if remoteCopy.Archived { if remoteCopy.Archived {
msh.WriteToPtyBuffer("cannot launch archived remote\n") msh.WriteToPtyBuffer("cannot launch archived remote\n")