pprofsrv

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pprofsrv runs the opt-in net/http/pprof listener. Profiling endpoints are unauthenticated and can leak memory contents, so the listener is off by default, lives on its own mux and port (never DefaultServeMux or the main server mux), and refuses non-loopback addresses unless the operator explicitly overrides the guard. See docs/security/runtime-hardening.md.

Index

Constants

View Source
const (
	EnvAddr        = "CONSOLE_PPROF_ADDR"
	EnvAllowRemote = "CONSOLE_PPROF_ALLOW_REMOTE"
)

Environment variables controlling the listener.

Variables

This section is empty.

Functions

func CheckAddr

func CheckAddr(addr string) error

CheckAddr returns an error unless addr is a host:port bound to loopback ("localhost" or a loopback IP literal). Hostnames other than "localhost" are refused rather than resolved, and an empty host (":6060") means all interfaces and is refused.

func FromEnv

func FromEnv() (addr string, allowRemote bool)

FromEnv reads the pprof address and remote override from the environment. An empty addr means pprof is disabled.

func Handler

func Handler() http.Handler

Handler returns a dedicated mux serving the pprof endpoints under /debug/pprof/. It does not touch http.DefaultServeMux.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a running pprof listener.

func Start

func Start(addr string, allowRemote bool) (*Server, error)

Start validates addr (unless allowRemote) and begins serving pprof. It binds synchronously so a refused or unbindable address is returned as an error the caller can treat as a startup failure. An empty addr returns (nil, nil): pprof disabled.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the bound listener address.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the listener, falling back to a hard close if ctx expires (long-running profile requests would otherwise block shutdown). It is safe to call on a nil Server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL