DaWesen commented on code in PR #3695:
URL: https://github.com/apache/dubbo-go/pull/3695#discussion_r3841328556
##########
loader.go:
##########
@@ -67,6 +68,23 @@ var watcher = &fileWatcher{
stopCh: make(chan struct{}),
}
+// goSafely runs fn in a new goroutine and recovers from any panic it raises,
+// preserving the recover and WaitGroup semantics of the former
+// gost/runtime.GoSafely helper so that a panicking watcher cannot crash the
+// process.
+func goSafely(wg *sync.WaitGroup, fn func()) {
+ wg.Add(1)
+ go func() {
+ defer func() {
+ if r := recover(); r != nil {
+ fmt.Fprintf(os.Stderr, "%s goroutine panic:
%v\n%s\n", time.Now(), r, debug.Stack())
+ }
+ wg.Done()
+ }()
+ fn()
+ }()
+}
Review Comment:
已采用此方案
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]