added some code to exit the whole process upon panic in http goroutines

This commit is contained in:
2024-12-08 00:57:58 +09:00
parent c81e05b4a3
commit 1496951c36
5 changed files with 107 additions and 4 deletions

10
hodu.go
View File

@ -1,5 +1,8 @@
package hodu
import "net/http"
import "os"
import "runtime"
import "sync"
const HODU_RPC_VERSION uint32 = 0x010000
@ -39,3 +42,10 @@ func tcp_addr_str_class(addr string) string {
return "tcp"
}
func dump_call_frame_and_exit(log Logger, req *http.Request, err interface{}) {
var buf []byte
buf = make([]byte, 65536); buf = buf[:min(65536, runtime.Stack(buf, false))]
log.Write("", LOG_ERROR, "[%s] %s %s - %v\n%s", req.RemoteAddr, req.Method, req.URL.String(), err, string(buf))
os.Exit(99) // fatal error. treat panic() as a fatal runtime error
}