Skip to content

Commit

Permalink
main: Add read header timeout to profile server.
Browse files Browse the repository at this point in the history
The profiling server typically shouldn't be exposed to the public, so
this doesn't make a huge difference, but it's still good practice for
HTTP servers to have read timeouts.
  • Loading branch information
davecgh committed Sep 18, 2023
1 parent 5204b35 commit b692b88
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dcrd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"runtime/debug"
"runtime/pprof"
"strings"
"time"

"github.com/decred/dcrd/internal/blockchain"
"github.com/decred/dcrd/internal/blockchain/indexers"
Expand Down Expand Up @@ -109,12 +110,16 @@ func dcrdMain() error {
if cfg.Profile != "" {
go func() {
listenAddr := cfg.Profile
dcrdLog.Infof("Creating profiling server "+
"listening on %s", listenAddr)
dcrdLog.Infof("Creating profiling server listening on %s",
listenAddr)
profileRedirect := http.RedirectHandler("/debug/pprof",
http.StatusSeeOther)
http.Handle("/", profileRedirect)
err := http.ListenAndServe(listenAddr, nil)
server := &http.Server{
Addr: listenAddr,
ReadHeaderTimeout: time.Second * 3,
}
err := server.ListenAndServe()
if err != nil {
fatalf(err.Error())
}
Expand Down

0 comments on commit b692b88

Please sign in to comment.