From 57cd7738c29e1f1bc7ceb0b73b06884902a79696 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 8 Dec 2020 16:45:34 -0800 Subject: [PATCH] tsweb: add an endpoint to manually trigger a GC. Signed-off-by: David Anderson --- tsweb/tsweb.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index 134f034cf..411e615a4 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -44,6 +44,16 @@ func registerCommonDebug(mux *http.ServeMux) { mux.Handle("/debug/pprof/", Protected(http.DefaultServeMux)) // to net/http/pprof mux.Handle("/debug/vars", Protected(http.DefaultServeMux)) // to expvar mux.Handle("/debug/varz", Protected(http.HandlerFunc(varzHandler))) + mux.Handle("/debug/gc", Protected(http.HandlerFunc(gcHandler))) +} + +func gcHandler(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("running GC...\n")) + if f, ok := w.(http.Flusher); ok { + f.Flush() + } + runtime.GC() + w.Write([]byte("Done.\n")) } func DefaultCertDir(leafDir string) string {