mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-20 00:03:53 +01:00
fix: add startup timeout guard to prevent indefinite hangs
Add a 10-second timeout mechanism during application initialization. If initialization fails to complete within the timeout window, the application logs a fatal error and exits. This prevents the proxy from becoming unresponsive during startup due to blocking operations in parallel initialization tasks (DNS providers, icon cache, system info poller, middleware loading, Docker client, API server, debug server, config watcher). The timeout guard uses a background goroutine that listens for either a completion signal (via closing the done channel) or the timeout expiration, providing a safety net for long-running or blocked initialization scenarios.
This commit is contained in:
13
cmd/main.go
13
cmd/main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/internal/api"
|
||||
@@ -32,6 +33,16 @@ func parallel(fns ...func()) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
done := make(chan struct{}, 1)
|
||||
go func() {
|
||||
select {
|
||||
case <-done:
|
||||
return
|
||||
case <-time.After(time.Second * 10):
|
||||
log.Fatal().Msgf("timeout waiting for initialization to complete, exiting...")
|
||||
}
|
||||
}()
|
||||
|
||||
initProfiling()
|
||||
|
||||
logging.InitLogger(os.Stderr, memlogger.GetMemLogger())
|
||||
@@ -86,6 +97,8 @@ func main() {
|
||||
uptime.Poller.Start()
|
||||
config.WatchChanges()
|
||||
|
||||
close(done)
|
||||
|
||||
task.WaitExit(config.Value().TimeoutShutdown)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user