Skip to content

cmd/server: pprof server serves nothing (net/http/pprof not imported) and log.Fatal on port conflict kills the process #273

Description

@whywaita

Problem

main (cmd/server/cmd.go:36-40) sets up what looks like a profiling endpoint:

runtime.SetBlockProfileRate(1)
runtime.SetMutexProfileFraction(1)
go func() {
	log.Fatal(http.ListenAndServe("localhost:6060", nil))
}()
  • net/http/pprof is not imported, so nothing is registered on http.DefaultServeMuxlocalhost:6060 only returns 404. The server is dead weight.
  • log.Fatal inside the goroutine terminates the whole myshoes process if port 6060 is taken (e.g. two instances on one host).
  • SetBlockProfileRate(1) / SetMutexProfileFraction(1) sample every blocking/mutex event unconditionally in production, which has measurable overhead.

Suggested fix

  • Import _ "net/http/pprof" so the endpoint actually works.
  • Log the listen error instead of log.Fatal.
  • Gate the debug server and the profile rates behind an env var (e.g. MYSHOES_PPROF=1), or at least use saner rates.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions