Skip to content

Commit

Permalink
feat: dynamically allocate a TCP port when STEAMPIPE_PPROF environmen…
Browse files Browse the repository at this point in the history
…t variable is set (#695)

Especially useful when multiple plugins are used
  • Loading branch information
pdecat authored Nov 17, 2023
1 parent 51f9c48 commit cbe797f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plugin/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -86,7 +87,13 @@ func Serve(opts *ServeOpts) {
if _, found := os.LookupEnv("STEAMPIPE_PPROF"); found {
log.Printf("[INFO] PROFILING!!!!")
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
listener, err := net.Listen("tcp", "localhost:0")
if err != nil {
log.Println(err)
return
}
log.Printf("[INFO] Check http://localhost:%d/debug/pprof/", listener.Addr().(*net.TCPAddr).Port)
log.Println(http.Serve(listener, nil))
}()
}
// TODO add context into all of these handlers
Expand Down

0 comments on commit cbe797f

Please # to comment.