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
@@ -5,6 +5,7 @@ package plugins
import (
"errors"
"fmt"
"log"
"runtime"
"syscall"
"unsafe"
@@ -22,6 +23,11 @@ func loadNativePlugin(data []byte) (NativePlugin, error) {
ch := make(chan initResult, 1)
go func() {
defer func() {
if r := recover(); r != nil {
ch <- initResult{err: fmt.Errorf("plugin init panic: %v", r)}
}
}()
runtime.LockOSThread()
mm, err := LoadMemoryModule(data)
@@ -170,6 +176,11 @@ func (p *dllPlugin) Event(event string, payload []byte) error {
copy(payloadCopy, payload)
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("[panic] plugin event panic: %v", r)
}
}()
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@@ -77,6 +77,11 @@ func (m *Manager) Load(ctx context.Context, manifest PluginManifest, binary []by
Payload: payloadVal,
}
go func() {
defer func() {
if r := recover(); r != nil {
log.Printf("[panic] plugin event send: %v", r)
}
}()
sendCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := wire.WriteMsg(sendCtx, m.writer, msg); err != nil {