修复代理与日志链路的可靠性问题
This commit is contained in:
@@ -30,7 +30,7 @@ type shutdownStep struct {
|
||||
run func(context.Context) error
|
||||
}
|
||||
|
||||
func waitForShutdown(stop <-chan os.Signal, serverErr <-chan error) error {
|
||||
func waitForShutdown(stop <-chan struct{}, serverErr <-chan error) error {
|
||||
select {
|
||||
case <-stop:
|
||||
log.Printf("[main] shutdown signal received")
|
||||
@@ -83,11 +83,9 @@ func run() error {
|
||||
}
|
||||
log.Printf("[main] filter mode=%s patterns=%d", filter.Mode, len(filter.Patterns))
|
||||
|
||||
stop := make(chan os.Signal, 1)
|
||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
||||
defer signal.Stop(stop)
|
||||
|
||||
rootCtx, cancel := context.WithCancel(context.Background())
|
||||
rootCtx, stopSignals := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer stopSignals()
|
||||
rootCtx, cancel := context.WithCancel(rootCtx)
|
||||
defer cancel()
|
||||
|
||||
pool := db.NewPool(rootCtx, cfg.ClickHouseURL, cfg.DBReconnectInterval)
|
||||
@@ -101,6 +99,7 @@ func run() error {
|
||||
SSEIdleTimeout: cfg.UpstreamStreamIdleTimeout,
|
||||
UpstreamTLSInsecureSkipVerify: cfg.UpstreamTLSInsecureSkipVerify,
|
||||
TrustedProxies: cfg.TrustedProxies,
|
||||
MaxRequestBytes: cfg.MaxRequestBytes,
|
||||
})
|
||||
|
||||
srv := &http.Server{
|
||||
@@ -118,7 +117,7 @@ func run() error {
|
||||
serverErr <- srv.ListenAndServe()
|
||||
}()
|
||||
|
||||
runErr := waitForShutdown(stop, serverErr)
|
||||
runErr := waitForShutdown(rootCtx.Done(), serverErr)
|
||||
|
||||
// HTTP、升级连接、日志排空和数据库共享同一个关闭总预算。
|
||||
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
|
||||
Reference in New Issue
Block a user