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 authored and jholdstock committed Sep 19, 2023
1 parent 89a2ed8 commit 1439f2d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dcrpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"runtime"
"strings"
"sync"
"time"

"github.com/decred/dcrd/rpcclient/v8"
"github.com/decred/dcrpool/internal/gui"
Expand Down Expand Up @@ -160,14 +161,17 @@ func realMain() error {
// Start the profiler.
go func() {
listenAddr := cfg.Profile
mpLog.Infof("Creating profiling server listening "+
"on %s", listenAddr)
mpLog.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 {
mpLog.Criticalf(err.Error())
mpLog.Critical(err)
cancel()
}
}()
Expand Down

0 comments on commit 1439f2d

Please sign in to comment.