Fix context usages (#35348)

This commit is contained in:
wxiaoguang
2025-08-27 19:00:01 +08:00
committed by GitHub
parent da5ce5c8e7
commit e837c998b7
48 changed files with 98 additions and 100 deletions

View File

@ -236,15 +236,16 @@ func serveInstalled(c *cli.Command) error {
}
func servePprof() {
// FIXME: it shouldn't use the global DefaultServeMux, and it should use a proper context
http.DefaultServeMux.Handle("/debug/fgprof", fgprof.Handler())
_, _, finished := process.GetManager().AddTypedContext(context.Background(), "Web: PProf Server", process.SystemProcessType, true)
// The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment it's not worth to introduce a configurable option for it.
_, _, finished := process.GetManager().AddTypedContext(context.TODO(), "Web: PProf Server", process.SystemProcessType, true)
// The pprof server is for debug purpose only, it shouldn't be exposed on public network. At the moment, it's not worth introducing a configurable option for it.
log.Info("Starting pprof server on localhost:6060")
log.Info("Stopped pprof server: %v", http.ListenAndServe("localhost:6060", nil))
finished()
}
func runWeb(_ context.Context, cmd *cli.Command) error {
func runWeb(ctx context.Context, cmd *cli.Command) error {
defer func() {
if panicked := recover(); panicked != nil {
log.Fatal("PANIC: %v\n%s", panicked, log.Stack(2))
@ -255,7 +256,7 @@ func runWeb(_ context.Context, cmd *cli.Command) error {
return fmt.Errorf("unknown command: %s", subCmdName)
}
managerCtx, cancel := context.WithCancel(context.Background())
managerCtx, cancel := context.WithCancel(ctx)
graceful.InitManager(managerCtx)
defer cancel()