Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions server/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"math"
"net/http"
"net/http/pprof"
"os"
"path/filepath"
"runtime/debug"
"strings"
"time"

"github.com/containers/storage/pkg/idtools"
"github.com/cri-o/cri-o/internal/lib/sandbox"
Expand Down Expand Up @@ -186,5 +191,25 @@ func (s *Server) GetInfoMux(enableProfile bool) *bone.Mux {
mux.Get("/debug/pprof/*", http.HandlerFunc(pprof.Index))
}

if enableProfile {
mux.Get("/debug/dumpheap", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
dumpFilePath := filepath.Join("/tmp", fmt.Sprintf(
"crio-heapdump-%s.out",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: Add a subcommand to crio-status to dump to a specific file location.

strings.ReplaceAll(time.Now().Format(time.RFC3339), ":", ""),
))
f, err := os.Create(dumpFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
defer f.Close()

debug.WriteHeapDump(f.Fd())

if _, err := w.Write([]byte(fmt.Sprintf("Wrote crio heapdump to %q. Please move it to avoid using memory.\n", dumpFilePath))); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opt.semgrep.no-printf-in-responsewriter: Detected printf or similar in http.ResponseWriter.write().
This bypasses HTML escaping that prevents cross-site scripting
vulnerabilities. Instead, use the 'html/template' package
to render data to users.

(at-me in a reply with help or ignore)

http.Error(w, fmt.Sprintf("unable to write heap dump status: %v", err), http.StatusInternalServerError)
}
}))
}

return mux
}