mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
ipn/localapi, client/tailscale: add a goroutine dump handler
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
1ca3e739f7
commit
a4b585947d
@ -88,3 +88,23 @@ func WhoIs(ctx context.Context, remoteAddr string) (*tailcfg.WhoIsResponse, erro
|
|||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Goroutines(ctx context.Context) ([]byte, error) {
|
||||||
|
req, err := http.NewRequestWithContext(ctx, "GET", "http://local-tailscaled.sock/localapi/v0/goroutines", nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
res, err := DoLocalRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if res.StatusCode != 200 {
|
||||||
|
return nil, fmt.Errorf("HTTP %s: %s", res.Status, body)
|
||||||
|
}
|
||||||
|
return body, nil
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
"tailscale.com/ipn/ipnlocal"
|
"tailscale.com/ipn/ipnlocal"
|
||||||
@ -53,6 +54,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/localapi/v0/whois":
|
case "/localapi/v0/whois":
|
||||||
h.serveWhoIs(w, r)
|
h.serveWhoIs(w, r)
|
||||||
|
case "/localapi/v0/goroutines":
|
||||||
|
h.serveGoroutines(w, r)
|
||||||
default:
|
default:
|
||||||
io.WriteString(w, "tailscaled\n")
|
io.WriteString(w, "tailscaled\n")
|
||||||
}
|
}
|
||||||
@ -93,3 +96,16 @@ func (h *Handler) serveWhoIs(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.Write(j)
|
w.Write(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) serveGoroutines(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Require write access out of paranoia that the goroutine dump
|
||||||
|
// (at least its arguments) might contain something sensitive.
|
||||||
|
if !h.PermitWrite {
|
||||||
|
http.Error(w, "goroutine dump access denied", http.StatusForbidden)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
buf := make([]byte, 2<<20)
|
||||||
|
buf = buf[:runtime.Stack(buf, true)]
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
w.Write(buf)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user