修复:weblive 协程 panic 防护、Mongo 空指针防护、直播状态轮询退避
Made-with: Cursor
This commit is contained in:
15
server/pkg/weblive/safe.go
Normal file
15
server/pkg/weblive/safe.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package weblive
|
||||
|
||||
import "log"
|
||||
|
||||
// goSafe 在独立 goroutine 中运行 fn;panic 只记录日志,避免拖垮整个 HTTP 进程(否则 Nginx 会看到 502)。
|
||||
func goSafe(label string, fn func()) {
|
||||
go func() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Printf("weblive: panic in %s: %v", label, r)
|
||||
}
|
||||
}()
|
||||
fn()
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user