Add optional pprof endpoint for debugging

This commit is contained in:
2026-07-04 21:31:53 +07:00
parent dca1363ec9
commit d5192e1cf7
3 changed files with 16 additions and 0 deletions
+13
View File
@@ -4,6 +4,7 @@ import (
"context"
"log/slog"
"net/http"
_ "net/http/pprof" // registers /debug/pprof on http.DefaultServeMux (served only on PprofAddr)
"os"
"github.com/golang-migrate/migrate/v4"
@@ -48,6 +49,18 @@ func main() {
go scheduler.New(st, orch).Start(context.Background())
// Optional pprof endpoint on a separate, non-published listener so we can
// pull live goroutine dumps (docker compose exec app wget -qO-
// localhost:6060/debug/pprof/goroutine?debug=2) without killing the process.
if cfg.PprofAddr != "" {
go func() {
slog.Info("pprof listening", "addr", cfg.PprofAddr)
if err := http.ListenAndServe(cfg.PprofAddr, nil); err != nil {
slog.Error("pprof serve", "err", err)
}
}()
}
slog.Info("listening", "addr", cfg.HTTPAddr)
if err := http.ListenAndServe(cfg.HTTPAddr, srv.Router()); err != nil {
slog.Error("serve", "err", err)