mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-04 23:52:29 +01:00
fix all panichandlers for the new format (inline recover()) (#1659)
This commit is contained in:
parent
7d0fb0391f
commit
fe91d167b6
@ -120,7 +120,9 @@ func panicTelemetryHandler() {
|
||||
}
|
||||
|
||||
func sendTelemetryWrapper() {
|
||||
defer panichandler.PanicHandler("sendTelemetryWrapper")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("sendTelemetryWrapper", recover())
|
||||
}()
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancelFn()
|
||||
beforeSendActivityUpdate(ctx)
|
||||
@ -270,7 +272,9 @@ func main() {
|
||||
}
|
||||
panichandler.PanicTelemetryHandler = panicTelemetryHandler
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("InitCustomShellStartupFiles")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("InitCustomShellStartupFiles", recover())
|
||||
}()
|
||||
err := shellutil.InitCustomShellStartupFiles()
|
||||
if err != nil {
|
||||
log.Printf("error initializing wsh and shell-integration files: %v\n", err)
|
||||
|
@ -60,7 +60,9 @@ func handleNewListenerConn(conn net.Conn, router *wshutil.WshRouter) {
|
||||
var routeIdContainer atomic.Pointer[string]
|
||||
proxy := wshutil.MakeRpcProxy()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("handleNewListenerConn:AdaptOutputChToStream")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleNewListenerConn:AdaptOutputChToStream", recover())
|
||||
}()
|
||||
writeErr := wshutil.AdaptOutputChToStream(proxy.ToRemoteCh, conn)
|
||||
if writeErr != nil {
|
||||
log.Printf("error writing to domain socket: %v\n", writeErr)
|
||||
@ -68,7 +70,9 @@ func handleNewListenerConn(conn net.Conn, router *wshutil.WshRouter) {
|
||||
}()
|
||||
go func() {
|
||||
// when input is closed, close the connection
|
||||
defer panichandler.PanicHandler("handleNewListenerConn:AdaptStreamToMsgCh")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleNewListenerConn:AdaptStreamToMsgCh", recover())
|
||||
}()
|
||||
defer func() {
|
||||
conn.Close()
|
||||
routeIdPtr := routeIdContainer.Load()
|
||||
@ -145,7 +149,9 @@ func serverRunRouter() error {
|
||||
rawCh := make(chan []byte, wshutil.DefaultOutputChSize)
|
||||
go packetparser.Parse(os.Stdin, termProxy.FromRemoteCh, rawCh)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("serverRunRouter:WritePackets")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("serverRunRouter:WritePackets", recover())
|
||||
}()
|
||||
for msg := range termProxy.ToRemoteCh {
|
||||
packetparser.WritePacket(os.Stdout, msg)
|
||||
}
|
||||
|
@ -426,7 +426,9 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
||||
ptyBuffer := wshutil.MakePtyBuffer(wshutil.WaveOSCPrefix, shellProc.Cmd, wshProxy.FromRemoteCh)
|
||||
go func() {
|
||||
// handles regular output from the pty (goes to the blockfile and xterm)
|
||||
defer panichandler.PanicHandler("blockcontroller:shellproc-pty-read-loop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("blockcontroller:shellproc-pty-read-loop", recover())
|
||||
}()
|
||||
defer func() {
|
||||
log.Printf("[shellproc] pty-read loop done\n")
|
||||
shellProc.Close()
|
||||
@ -463,7 +465,9 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
||||
go func() {
|
||||
// handles input from the shellInputCh, sent to pty
|
||||
// use shellInputCh instead of bc.ShellInputCh (because we want to be attached to *this* ch. bc.ShellInputCh can be updated)
|
||||
defer panichandler.PanicHandler("blockcontroller:shellproc-input-loop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("blockcontroller:shellproc-input-loop", recover())
|
||||
}()
|
||||
for ic := range shellInputCh {
|
||||
if len(ic.InputData) > 0 {
|
||||
shellProc.Cmd.Write(ic.InputData)
|
||||
@ -481,7 +485,9 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("blockcontroller:shellproc-output-loop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("blockcontroller:shellproc-output-loop", recover())
|
||||
}()
|
||||
// handles outputCh -> shellInputCh
|
||||
for msg := range wshProxy.ToRemoteCh {
|
||||
encodedMsg, err := wshutil.EncodeWaveOSCBytes(wshutil.WaveServerOSC, msg)
|
||||
@ -492,7 +498,9 @@ func (bc *BlockController) DoRunShellCommand(rc *RunShellOpts, blockMeta waveobj
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("blockcontroller:shellproc-wait-loop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("blockcontroller:shellproc-wait-loop", recover())
|
||||
}()
|
||||
// wait for the shell to finish
|
||||
var exitCode int
|
||||
defer func() {
|
||||
@ -631,7 +639,9 @@ func (bc *BlockController) run(bdata *waveobj.Block, blockMeta map[string]any, r
|
||||
}
|
||||
runningShellCommand = true
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("blockcontroller:run-shell-command")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("blockcontroller:run-shell-command", recover())
|
||||
}()
|
||||
defer bc.UnlockRunLock()
|
||||
var termSize waveobj.TermSize
|
||||
if rtOpts != nil {
|
||||
|
@ -514,7 +514,9 @@ func (s *FileStore) runFlushWithNewContext() (FlushStats, error) {
|
||||
}
|
||||
|
||||
func (s *FileStore) runFlusher() {
|
||||
defer panichandler.PanicHandler("filestore flusher")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("filestore flusher", recover())
|
||||
}()
|
||||
for {
|
||||
stats, err := s.runFlushWithNewContext()
|
||||
if err != nil || stats.NumDirtyEntries > 0 {
|
||||
|
@ -13,31 +13,29 @@ import (
|
||||
// gets around import cycles
|
||||
var PanicTelemetryHandler func()
|
||||
|
||||
func PanicHandlerNoTelemetry(debugStr string) {
|
||||
r := recover()
|
||||
if r == nil {
|
||||
func PanicHandlerNoTelemetry(debugStr string, recoverVal any) {
|
||||
if recoverVal == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("[panic] in %s: %v\n", debugStr, r)
|
||||
log.Printf("[panic] in %s: %v\n", debugStr, recoverVal)
|
||||
debug.PrintStack()
|
||||
}
|
||||
|
||||
// returns an error (wrapping the panic) if a panic occurred
|
||||
func PanicHandler(debugStr string) error {
|
||||
r := recover()
|
||||
if r == nil {
|
||||
func PanicHandler(debugStr string, recoverVal any) error {
|
||||
if recoverVal == nil {
|
||||
return nil
|
||||
}
|
||||
log.Printf("[panic] in %s: %v\n", debugStr, r)
|
||||
log.Printf("[panic] in %s: %v\n", debugStr, recoverVal)
|
||||
debug.PrintStack()
|
||||
if PanicTelemetryHandler != nil {
|
||||
go func() {
|
||||
defer PanicHandlerNoTelemetry("PanicTelemetryHandler")
|
||||
defer PanicHandlerNoTelemetry("PanicTelemetryHandler", recover())
|
||||
PanicTelemetryHandler()
|
||||
}()
|
||||
}
|
||||
if err, ok := r.(error); ok {
|
||||
if err, ok := recoverVal.(error); ok {
|
||||
return fmt.Errorf("panic in %s: %w", debugStr, err)
|
||||
}
|
||||
return fmt.Errorf("panic in %s: %v", debugStr, r)
|
||||
return fmt.Errorf("panic in %s: %v", debugStr, recoverVal)
|
||||
}
|
||||
|
@ -198,7 +198,9 @@ func (conn *SSHConn) OpenDomainSocketListener() error {
|
||||
conn.DomainSockListener = listener
|
||||
})
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("conncontroller:OpenDomainSocketListener")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("conncontroller:OpenDomainSocketListener", recover())
|
||||
}()
|
||||
defer conn.WithLock(func() {
|
||||
conn.DomainSockListener = nil
|
||||
conn.SockName = ""
|
||||
@ -258,7 +260,9 @@ func (conn *SSHConn) StartConnServer() error {
|
||||
})
|
||||
// service the I/O
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("conncontroller:sshSession.Wait")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("conncontroller:sshSession.Wait", recover())
|
||||
}()
|
||||
// wait for termination, clear the controller
|
||||
defer conn.WithLock(func() {
|
||||
conn.ConnController = nil
|
||||
@ -267,7 +271,9 @@ func (conn *SSHConn) StartConnServer() error {
|
||||
log.Printf("conn controller (%q) terminated: %v", conn.GetName(), waitErr)
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("conncontroller:sshSession-output")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("conncontroller:sshSession-output", recover())
|
||||
}()
|
||||
readErr := wshutil.StreamToLines(pipeRead, func(line []byte) {
|
||||
lineStr := string(line)
|
||||
if !strings.HasSuffix(lineStr, "\n") {
|
||||
|
@ -274,7 +274,9 @@ func CpHostToRemote(client *ssh.Client, sourcePath string, destPath string) erro
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("connutil:CpHostToRemote")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("connutil:CpHostToRemote", recover())
|
||||
}()
|
||||
io.Copy(installStdin, input)
|
||||
session.Close() // this allows the command to complete for reasons i don't fully understand
|
||||
}()
|
||||
|
@ -720,9 +720,9 @@ func ConnectToClient(connCtx context.Context, opts *SSHOpts, currentClient *ssh.
|
||||
// when given unexpected strings
|
||||
func findSshConfigKeywords(hostPattern string) (connKeywords *wshrpc.ConnKeywords, outErr error) {
|
||||
defer func() {
|
||||
err := panichandler.PanicHandler("sshclient:find-ssh-config-keywords")
|
||||
if err != nil {
|
||||
outErr = err
|
||||
panicErr := panichandler.PanicHandler("sshclient:find-ssh-config-keywords", recover())
|
||||
if panicErr != nil {
|
||||
outErr = panicErr
|
||||
}
|
||||
}()
|
||||
WaveSshConfigUserSettings().ReloadConfigs()
|
||||
|
@ -151,7 +151,9 @@ func (svc *WindowService) SwitchWorkspace(ctx context.Context, windowId string,
|
||||
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WindowService:SwitchWorkspace:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WindowService:SwitchWorkspace:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return ws, err
|
||||
|
@ -59,7 +59,9 @@ func (svc *WorkspaceService) UpdateWorkspace(ctx context.Context, workspaceId st
|
||||
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:UpdateWorkspace:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:UpdateWorkspace:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return updates, nil
|
||||
@ -104,7 +106,9 @@ func (svc *WorkspaceService) DeleteWorkspace(workspaceId string) (waveobj.Update
|
||||
}
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:DeleteWorkspace:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:DeleteWorkspace:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return updates, claimableWorkspace, nil
|
||||
@ -153,7 +157,9 @@ func (svc *WorkspaceService) CreateTab(workspaceId string, tabName string, activ
|
||||
}
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:CreateTab:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:CreateTab:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return tabId, updates, nil
|
||||
@ -174,7 +180,9 @@ func (svc *WorkspaceService) ChangeTabPinning(ctx context.Context, workspaceId s
|
||||
}
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:ChangeTabPinning:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:ChangeTabPinning:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return updates, nil
|
||||
@ -224,7 +232,9 @@ func (svc *WorkspaceService) SetActiveTab(workspaceId string, tabId string) (wav
|
||||
}
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:SetActiveTab:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:SetActiveTab:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
var extraUpdates waveobj.UpdatesRtnType
|
||||
@ -270,7 +280,9 @@ func (svc *WorkspaceService) CloseTab(ctx context.Context, workspaceId string, t
|
||||
}
|
||||
updates := waveobj.ContextGetUpdatesRtn(ctx)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WorkspaceService:CloseTab:SendUpdateEvents")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WorkspaceService:CloseTab:SendUpdateEvents", recover())
|
||||
}()
|
||||
wps.Broker.SendUpdateEvents(updates)
|
||||
}()
|
||||
return rtn, updates, nil
|
||||
|
@ -76,7 +76,9 @@ func (cw CmdWrap) KillGraceful(timeout time.Duration) {
|
||||
cw.Cmd.Process.Signal(syscall.SIGTERM)
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("KillGraceful:Kill")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("KillGraceful:Kill", recover())
|
||||
}()
|
||||
time.Sleep(timeout)
|
||||
if cw.Cmd.ProcessState == nil || !cw.Cmd.ProcessState.Exited() {
|
||||
cw.Cmd.Process.Kill() // force kill if it is already not exited
|
||||
@ -208,7 +210,9 @@ func (wcw WslCmdWrap) KillGraceful(timeout time.Duration) {
|
||||
}
|
||||
process.Signal(os.Interrupt)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("KillGraceful-wsl:Kill")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("KillGraceful-wsl:Kill", recover())
|
||||
}()
|
||||
time.Sleep(timeout)
|
||||
process := wcw.WslCmd.GetProcess()
|
||||
processState := wcw.WslCmd.GetProcessState()
|
||||
|
@ -52,7 +52,9 @@ type ShellProc struct {
|
||||
func (sp *ShellProc) Close() {
|
||||
sp.Cmd.KillGraceful(DefaultGracefulKillWait)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("ShellProc.Close")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("ShellProc.Close", recover())
|
||||
}()
|
||||
waitErr := sp.Cmd.Wait()
|
||||
sp.SetWaitErrorAndSignalDone(waitErr)
|
||||
|
||||
@ -496,7 +498,7 @@ func RunSimpleCmdInPty(ecmd *exec.Cmd, termSize waveobj.TermSize) ([]byte, error
|
||||
ioDone := make(chan bool)
|
||||
var outputBuf bytes.Buffer
|
||||
go func() {
|
||||
panichandler.PanicHandler("RunSimpleCmdInPty:ioCopy")
|
||||
panichandler.PanicHandler("RunSimpleCmdInPty:ioCopy", recover())
|
||||
// ignore error (/dev/ptmx has read error when process is done)
|
||||
defer close(ioDone)
|
||||
io.Copy(&outputBuf, cmdPty)
|
||||
|
@ -83,7 +83,7 @@ func AutoUpdateChannel() string {
|
||||
// Wraps UpdateCurrentActivity, spawns goroutine, and logs errors
|
||||
func GoUpdateActivityWrap(update wshrpc.ActivityUpdate, debugStr string) {
|
||||
go func() {
|
||||
defer panichandler.PanicHandlerNoTelemetry("GoUpdateActivityWrap")
|
||||
defer panichandler.PanicHandlerNoTelemetry("GoUpdateActivityWrap", recover())
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancelFn()
|
||||
err := UpdateActivity(ctx, update)
|
||||
|
@ -114,7 +114,7 @@ func (AnthropicBackend) StreamCompletion(ctx context.Context, request wshrpc.Wav
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("AnthropicBackend.StreamCompletion")
|
||||
panicErr := panichandler.PanicHandler("AnthropicBackend.StreamCompletion", recover())
|
||||
if panicErr != nil {
|
||||
rtn <- makeAIError(panicErr)
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ func (WaveAICloudBackend) StreamCompletion(ctx context.Context, request wshrpc.W
|
||||
wsEndpoint := wcloud.GetWSEndpoint()
|
||||
go func() {
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("WaveAICloudBackend.StreamCompletion")
|
||||
panicErr := panichandler.PanicHandler("WaveAICloudBackend.StreamCompletion", recover())
|
||||
if panicErr != nil {
|
||||
rtn <- makeAIError(panicErr)
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (OpenAIBackend) StreamCompletion(ctx context.Context, request wshrpc.WaveAI
|
||||
rtn := make(chan wshrpc.RespOrErrorUnion[wshrpc.WaveAIPacketType])
|
||||
go func() {
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("OpenAIBackend.StreamCompletion")
|
||||
panicErr := panichandler.PanicHandler("OpenAIBackend.StreamCompletion", recover())
|
||||
if panicErr != nil {
|
||||
rtn <- makeAIError(panicErr)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (PerplexityBackend) StreamCompletion(ctx context.Context, request wshrpc.Wa
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("PerplexityBackend.StreamCompletion")
|
||||
panicErr := panichandler.PanicHandler("PerplexityBackend.StreamCompletion", recover())
|
||||
if panicErr != nil {
|
||||
rtn <- makeAIError(panicErr)
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (*WaveAppServerImpl) WshServerImpl() {}
|
||||
func (impl *WaveAppServerImpl) VDomRenderCommand(ctx context.Context, feUpdate vdom.VDomFrontendUpdate) chan wshrpc.RespOrErrorUnion[*vdom.VDomBackendUpdate] {
|
||||
respChan := make(chan wshrpc.RespOrErrorUnion[*vdom.VDomBackendUpdate], 5)
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("VDomRenderCommand")
|
||||
panicErr := panichandler.PanicHandler("VDomRenderCommand", recover())
|
||||
if panicErr != nil {
|
||||
respChan <- wshrpc.RespOrErrorUnion[*vdom.VDomBackendUpdate]{
|
||||
Error: panicErr,
|
||||
@ -88,7 +88,9 @@ func (impl *WaveAppServerImpl) VDomRenderCommand(ctx context.Context, feUpdate v
|
||||
// Split the update into chunks and send them sequentially
|
||||
updates := vdom.SplitBackendUpdate(update)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("VDomRenderCommand:splitUpdates")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("VDomRenderCommand:splitUpdates", recover())
|
||||
}()
|
||||
defer close(respChan)
|
||||
for _, splitUpdate := range updates {
|
||||
respChan <- wshrpc.RespOrErrorUnion[*vdom.VDomBackendUpdate]{
|
||||
@ -109,7 +111,7 @@ func (impl *WaveAppServerImpl) VDomUrlRequestCommand(ctx context.Context, data w
|
||||
defer writer.Close() // Ensures writer is closed before the channel is closed
|
||||
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("VDomUrlRequestCommand")
|
||||
panicErr := panichandler.PanicHandler("VDomUrlRequestCommand", recover())
|
||||
if panicErr != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
writer.Write([]byte(fmt.Sprintf("internal server error: %v", panicErr)))
|
||||
|
@ -65,7 +65,9 @@ func (w *Watcher) Start() {
|
||||
w.sendInitialValues()
|
||||
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("filewatcher:Start")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("filewatcher:Start", recover())
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case event, ok := <-w.watcher.Events:
|
||||
|
@ -94,7 +94,9 @@ func CreateBlock(ctx context.Context, tabId string, blockDef *waveobj.BlockDef,
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("CreateBlock:telemetry")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("CreateBlock:telemetry", recover())
|
||||
}()
|
||||
blockView := blockDef.Meta.GetString(waveobj.MetaKey_View, "")
|
||||
if blockView == "" {
|
||||
return
|
||||
|
@ -358,7 +358,7 @@ type ClientActiveState struct {
|
||||
func WebFnWrap(opts WebFnOpts, fn WebFnType) WebFnType {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
recErr := panichandler.PanicHandler("WebFnWrap")
|
||||
recErr := panichandler.PanicHandler("WebFnWrap", recover())
|
||||
if recErr == nil {
|
||||
return
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ func getStringFromMap(jmsg map[string]any, key string) string {
|
||||
func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan []byte) {
|
||||
var rtnErr error
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("processWSCommand")
|
||||
panicErr := panichandler.PanicHandler("processWSCommand", recover())
|
||||
if panicErr != nil {
|
||||
rtnErr = panicErr
|
||||
}
|
||||
@ -302,7 +302,9 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleWsInternal:outputCh")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleWsInternal:outputCh", recover())
|
||||
}()
|
||||
// no waitgroup add here
|
||||
// move values from rpcOutputCh to outputCh
|
||||
for msgBytes := range wproxy.ToRemoteCh {
|
||||
@ -314,13 +316,17 @@ func HandleWsInternal(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleWsInternal:ReadLoop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleWsInternal:ReadLoop", recover())
|
||||
}()
|
||||
// read loop
|
||||
defer wg.Done()
|
||||
ReadLoop(conn, outputCh, closeCh, wproxy.FromRemoteCh, routeId)
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleWsInternal:WriteLoop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleWsInternal:WriteLoop", recover())
|
||||
}()
|
||||
// write loop
|
||||
defer wg.Done()
|
||||
WriteLoop(conn, outputCh, closeCh, routeId)
|
||||
|
@ -40,7 +40,9 @@ func sendRpcRequestCallHelper[T any](w *wshutil.WshRpc, command string, data int
|
||||
|
||||
func rtnErr[T any](ch chan wshrpc.RespOrErrorUnion[T], err error) {
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("wshclientutil:rtnErr")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("wshclientutil:rtnErr", recover())
|
||||
}()
|
||||
ch <- wshrpc.RespOrErrorUnion[T]{Error: err}
|
||||
close(ch)
|
||||
}()
|
||||
@ -65,7 +67,9 @@ func sendRpcRequestResponseStreamHelper[T any](w *wshutil.WshRpc, command string
|
||||
reqHandler.SendCancel()
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("sendRpcRequestResponseStreamHelper")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("sendRpcRequestResponseStreamHelper", recover())
|
||||
}()
|
||||
defer close(respChan)
|
||||
for {
|
||||
if reqHandler.ResponseDone() {
|
||||
|
@ -47,7 +47,9 @@ func (*WshServer) WshServerImpl() {}
|
||||
var WshServerImpl = WshServer{}
|
||||
|
||||
func (ws *WshServer) TestCommand(ctx context.Context, data string) error {
|
||||
defer panichandler.PanicHandler("TestCommand")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("TestCommand", recover())
|
||||
}()
|
||||
rpcSource := wshutil.GetRpcSourceFromContext(ctx)
|
||||
log.Printf("TEST src:%s | %s\n", rpcSource, data)
|
||||
return nil
|
||||
@ -63,7 +65,9 @@ func (ws *WshServer) MessageCommand(ctx context.Context, data wshrpc.CommandMess
|
||||
func (ws *WshServer) StreamTestCommand(ctx context.Context) chan wshrpc.RespOrErrorUnion[int] {
|
||||
rtn := make(chan wshrpc.RespOrErrorUnion[int])
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("StreamTestCommand")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("StreamTestCommand", recover())
|
||||
}()
|
||||
for i := 1; i <= 5; i++ {
|
||||
rtn <- wshrpc.RespOrErrorUnion[int]{Response: i}
|
||||
time.Sleep(1 * time.Second)
|
||||
|
@ -132,7 +132,9 @@ func serverImplAdapter(impl any) func(*RpcResponseHandler) bool {
|
||||
return true
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("serverImplAdapter:responseStream")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("serverImplAdapter:responseStream", recover())
|
||||
}()
|
||||
defer handler.Finalize()
|
||||
// must use reflection here because we don't know the generic type of RespOrErrorUnion
|
||||
for {
|
||||
|
@ -113,7 +113,9 @@ func (p *WshRpcMultiProxy) handleUnauthMessage(msgBytes []byte) {
|
||||
p.setRouteInfo(routeInfo.AuthToken, routeInfo)
|
||||
p.sendAuthResponse(msg, routeId, routeInfo.AuthToken)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WshRpcMultiProxy:handleUnauthMessage")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WshRpcMultiProxy:handleUnauthMessage", recover())
|
||||
}()
|
||||
for msgBytes := range routeInfo.Proxy.ToRemoteCh {
|
||||
p.ToRemoteCh <- msgBytes
|
||||
}
|
||||
|
@ -92,7 +92,9 @@ func noRouteErr(routeId string) error {
|
||||
}
|
||||
|
||||
func (router *WshRouter) SendEvent(routeId string, event wps.WaveEvent) {
|
||||
defer panichandler.PanicHandler("WshRouter.SendEvent")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WshRouter.SendEvent", recover())
|
||||
}()
|
||||
rpc := router.GetRpc(routeId)
|
||||
if rpc == nil {
|
||||
return
|
||||
@ -298,7 +300,9 @@ func (router *WshRouter) RegisterRoute(routeId string, rpc AbstractRpcClient, sh
|
||||
}
|
||||
router.RouteMap[routeId] = rpc
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WshRouter:registerRoute:recvloop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WshRouter:registerRoute:recvloop", recover())
|
||||
}()
|
||||
// announce
|
||||
if shouldAnnounce && !alreadyExists && router.GetUpstreamClient() != nil {
|
||||
announceMsg := RpcMessage{Command: wshrpc.Command_RouteAnnounce, Source: routeId}
|
||||
@ -344,7 +348,9 @@ func (router *WshRouter) UnregisterRoute(routeId string) {
|
||||
}
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("WshRouter:unregisterRoute:routegone")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("WshRouter:unregisterRoute:routegone", recover())
|
||||
}()
|
||||
wps.Broker.UnsubscribeAll(routeId)
|
||||
wps.Broker.Publish(wps.WaveEvent{Event: wps.Event_RouteGone, Scopes: []string{routeId}})
|
||||
}()
|
||||
|
@ -304,13 +304,15 @@ func (w *WshRpc) handleRequest(req *RpcMessage) {
|
||||
w.registerResponseHandler(req.ReqId, respHandler)
|
||||
isAsync := false
|
||||
defer func() {
|
||||
panicErr := panichandler.PanicHandler("handleRequest")
|
||||
panicErr := panichandler.PanicHandler("handleRequest", recover())
|
||||
if panicErr != nil {
|
||||
respHandler.SendResponseError(panicErr)
|
||||
}
|
||||
if isAsync {
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("handleRequest:finalize")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleRequest:finalize", recover())
|
||||
}()
|
||||
<-ctx.Done()
|
||||
respHandler.Finalize()
|
||||
}()
|
||||
@ -343,7 +345,9 @@ func (w *WshRpc) runServer() {
|
||||
}
|
||||
if msg.IsRpcRequest() {
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("handleRequest:goroutine")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleRequest:goroutine", recover())
|
||||
}()
|
||||
w.handleRequest(&msg)
|
||||
}()
|
||||
} else {
|
||||
@ -388,7 +392,9 @@ func (w *WshRpc) registerRpc(ctx context.Context, reqId string) chan *RpcMessage
|
||||
Ctx: ctx,
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("registerRpc:timeout")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("registerRpc:timeout", recover())
|
||||
}()
|
||||
<-ctx.Done()
|
||||
w.unregisterRpc(reqId, fmt.Errorf("EC-TIME: timeout waiting for response"))
|
||||
}()
|
||||
@ -458,7 +464,9 @@ func (handler *RpcRequestHandler) Context() context.Context {
|
||||
}
|
||||
|
||||
func (handler *RpcRequestHandler) SendCancel() {
|
||||
defer panichandler.PanicHandler("SendCancel")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SendCancel", recover())
|
||||
}()
|
||||
msg := &RpcMessage{
|
||||
Cancel: true,
|
||||
ReqId: handler.reqId,
|
||||
@ -563,7 +571,9 @@ func (handler *RpcResponseHandler) SendMessage(msg string) {
|
||||
}
|
||||
|
||||
func (handler *RpcResponseHandler) SendResponse(data any, done bool) error {
|
||||
defer panichandler.PanicHandler("SendResponse")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SendResponse", recover())
|
||||
}()
|
||||
if handler.reqId == "" {
|
||||
return nil // no response expected
|
||||
}
|
||||
@ -588,7 +598,9 @@ func (handler *RpcResponseHandler) SendResponse(data any, done bool) error {
|
||||
}
|
||||
|
||||
func (handler *RpcResponseHandler) SendResponseError(err error) {
|
||||
defer panichandler.PanicHandler("SendResponseError")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SendResponseError", recover())
|
||||
}()
|
||||
if handler.reqId == "" || handler.done.Load() {
|
||||
return
|
||||
}
|
||||
@ -637,7 +649,9 @@ func (w *WshRpc) SendComplexRequest(command string, data any, opts *wshrpc.RpcOp
|
||||
if timeoutMs <= 0 {
|
||||
timeoutMs = DefaultTimeoutMs
|
||||
}
|
||||
defer panichandler.PanicHandler("SendComplexRequest")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SendComplexRequest", recover())
|
||||
}()
|
||||
if command == "" {
|
||||
return nil, fmt.Errorf("command cannot be empty")
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ func installShutdownSignalHandlers(quiet bool) {
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
|
||||
go func() {
|
||||
defer panichandler.PanicHandlerNoTelemetry("installShutdownSignalHandlers")
|
||||
defer panichandler.PanicHandlerNoTelemetry("installShutdownSignalHandlers", recover())
|
||||
for sig := range sigCh {
|
||||
DoShutdown(fmt.Sprintf("got signal %v", sig), 1, quiet)
|
||||
break
|
||||
@ -200,7 +200,9 @@ func SetupTerminalRpcClient(serverImpl ServerImpl) (*WshRpc, io.Reader) {
|
||||
ptyBuf := MakePtyBuffer(WaveServerOSCPrefix, os.Stdin, messageCh)
|
||||
rpcClient := MakeWshRpc(messageCh, outputCh, wshrpc.RpcContext{}, serverImpl)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("SetupTerminalRpcClient")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SetupTerminalRpcClient", recover())
|
||||
}()
|
||||
for msg := range outputCh {
|
||||
barr, err := EncodeWaveOSCBytes(WaveOSC, msg)
|
||||
if err != nil {
|
||||
@ -221,7 +223,9 @@ func SetupPacketRpcClient(input io.Reader, output io.Writer, serverImpl ServerIm
|
||||
rpcClient := MakeWshRpc(messageCh, outputCh, wshrpc.RpcContext{}, serverImpl)
|
||||
go packetparser.Parse(input, messageCh, rawCh)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("SetupPacketRpcClient:outputloop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SetupPacketRpcClient:outputloop", recover())
|
||||
}()
|
||||
for msg := range outputCh {
|
||||
packetparser.WritePacket(output, msg)
|
||||
}
|
||||
@ -234,7 +238,9 @@ func SetupConnRpcClient(conn net.Conn, serverImpl ServerImpl) (*WshRpc, chan err
|
||||
outputCh := make(chan []byte, DefaultOutputChSize)
|
||||
writeErrCh := make(chan error, 1)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("SetupConnRpcClient:AdaptOutputChToStream")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SetupConnRpcClient:AdaptOutputChToStream", recover())
|
||||
}()
|
||||
writeErr := AdaptOutputChToStream(outputCh, conn)
|
||||
if writeErr != nil {
|
||||
writeErrCh <- writeErr
|
||||
@ -242,7 +248,9 @@ func SetupConnRpcClient(conn net.Conn, serverImpl ServerImpl) (*WshRpc, chan err
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("SetupConnRpcClient:AdaptStreamToMsgCh")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SetupConnRpcClient:AdaptStreamToMsgCh", recover())
|
||||
}()
|
||||
// when input is closed, close the connection
|
||||
defer conn.Close()
|
||||
AdaptStreamToMsgCh(conn, inputCh)
|
||||
@ -270,7 +278,9 @@ func SetupDomainSocketRpcClient(sockName string, serverImpl ServerImpl) (*WshRpc
|
||||
}
|
||||
rtn, errCh, err := SetupConnRpcClient(conn, serverImpl)
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("SetupDomainSocketRpcClient:closeConn")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("SetupDomainSocketRpcClient:closeConn", recover())
|
||||
}()
|
||||
defer conn.Close()
|
||||
err := <-errCh
|
||||
if err != nil && err != io.EOF {
|
||||
@ -417,11 +427,15 @@ func HandleStdIOClient(logName string, input io.Reader, output io.Writer) {
|
||||
proxy.DisposeRoutes()
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleStdIOClient:RunUnauthLoop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleStdIOClient:RunUnauthLoop", recover())
|
||||
}()
|
||||
proxy.RunUnauthLoop()
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleStdIOClient:ToRemoteChLoop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleStdIOClient:ToRemoteChLoop", recover())
|
||||
}()
|
||||
defer closeDoneCh()
|
||||
for msg := range proxy.ToRemoteCh {
|
||||
err := packetparser.WritePacket(output, msg)
|
||||
@ -432,7 +446,9 @@ func HandleStdIOClient(logName string, input io.Reader, output io.Writer) {
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("HandleStdIOClient:RawChLoop")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("HandleStdIOClient:RawChLoop", recover())
|
||||
}()
|
||||
defer closeDoneCh()
|
||||
for msg := range rawCh {
|
||||
log.Printf("[%s:stdout] %s", logName, msg)
|
||||
@ -445,7 +461,9 @@ func handleDomainSocketClient(conn net.Conn) {
|
||||
var routeIdContainer atomic.Pointer[string]
|
||||
proxy := MakeRpcProxy()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("handleDomainSocketClient:AdaptOutputChToStream")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleDomainSocketClient:AdaptOutputChToStream", recover())
|
||||
}()
|
||||
writeErr := AdaptOutputChToStream(proxy.ToRemoteCh, conn)
|
||||
if writeErr != nil {
|
||||
log.Printf("error writing to domain socket: %v\n", writeErr)
|
||||
@ -453,7 +471,9 @@ func handleDomainSocketClient(conn net.Conn) {
|
||||
}()
|
||||
go func() {
|
||||
// when input is closed, close the connection
|
||||
defer panichandler.PanicHandler("handleDomainSocketClient:AdaptStreamToMsgCh")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("handleDomainSocketClient:AdaptStreamToMsgCh", recover())
|
||||
}()
|
||||
defer func() {
|
||||
conn.Close()
|
||||
routeIdPtr := routeIdContainer.Load()
|
||||
|
@ -223,7 +223,9 @@ func CpHostToRemote(ctx context.Context, client *Distro, sourcePath string, dest
|
||||
return fmt.Errorf("cannot open local file %s to send to host: %v", sourcePath, err)
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("wslutil:cpHostToRemote:catStdin")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("wslutil:cpHostToRemote:catStdin", recover())
|
||||
}()
|
||||
io.Copy(catStdin, input)
|
||||
installStepCmds["cat"].Cancel()
|
||||
|
||||
|
@ -236,7 +236,9 @@ func (conn *WslConn) StartConnServer() error {
|
||||
})
|
||||
// service the I/O
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("wsl:StartConnServer:wait")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("wsl:StartConnServer:wait", recover())
|
||||
}()
|
||||
// wait for termination, clear the controller
|
||||
defer conn.WithLock(func() {
|
||||
conn.ConnController = nil
|
||||
@ -245,7 +247,9 @@ func (conn *WslConn) StartConnServer() error {
|
||||
log.Printf("conn controller (%q) terminated: %v", conn.GetName(), waitErr)
|
||||
}()
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("wsl:StartConnServer:handleStdIOClient")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("wsl:StartConnServer:handleStdIOClient", recover())
|
||||
}()
|
||||
logName := fmt.Sprintf("conncontroller:%s", conn.GetName())
|
||||
wshutil.HandleStdIOClient(logName, pipeRead, inputPipeWrite)
|
||||
}()
|
||||
|
@ -285,7 +285,9 @@ func DBDelete(ctx context.Context, otype string, id string) error {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
defer panichandler.PanicHandler("DBDelete:filestore.DeleteZone")
|
||||
defer func() {
|
||||
panichandler.PanicHandler("DBDelete:filestore.DeleteZone", recover())
|
||||
}()
|
||||
// we spawn a go routine here because we don't want to reuse the DB connection
|
||||
// since DBDelete is called in a transaction from DeleteTab
|
||||
deleteCtx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
|
Loading…
Reference in New Issue
Block a user