MCPcopy Index your code
hub / github.com/coder/coder / tryGettingCoderProviderStacktrace

Function tryGettingCoderProviderStacktrace

provisioner/terraform/provision.go:464–494  ·  view source on GitHub ↗

tryGettingCoderProviderStacktrace attempts to dial a special pprof endpoint we added to terraform-provider-coder in https://github.com/coder/terraform-provider-coder/pull/295 which shipped in v1.0.4. It will return the stacktraces of the provider, which will hopefully allow us to figure out why it

(sess *provisionersdk.Session)

Source from the content-addressed store, hash-verified

462// shipped in v1.0.4. It will return the stacktraces of the provider, which will hopefully allow us
463// to figure out why it hasn't exited.
464func tryGettingCoderProviderStacktrace(sess *provisionersdk.Session) string {
465 path := filepath.Clean(filepath.Join(sess.Files.WorkDirectory(), "../.coder/pprof"))
466 sess.Logger.Info(sess.Context(), "attempting to get stack traces", slog.F("path", path))
467 c := http.Client{
468 Transport: &http.Transport{
469 DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
470 d := net.Dialer{}
471 return d.DialContext(ctx, "unix", path)
472 },
473 },
474 }
475 req, err := http.NewRequestWithContext(sess.Context(), http.MethodGet,
476 "http://localhost/debug/pprof/goroutine?debug=2", nil)
477 if err != nil {
478 sess.Logger.Error(sess.Context(), "error creating GET request", slog.Error(err))
479 return ""
480 }
481 resp, err := c.Do(req)
482 if err != nil {
483 // Only log at Info here, since we only added the pprof endpoint to terraform-provider-coder
484 // in v1.0.4
485 sess.Logger.Info(sess.Context(), "could not GET stack traces", slog.Error(err))
486 return ""
487 }
488 defer resp.Body.Close()
489 stacktraces, err := io.ReadAll(resp.Body)
490 if err != nil {
491 sess.Logger.Error(sess.Context(), "could not read stack traces", slog.Error(err))
492 }
493 return string(stacktraces)
494}
495
496// gitAuthAccessTokenEnvironmentVariable is copied from
497// github.com/coder/terraform-provider-coder/provider.GitAuthAccessTokenEnvironmentVariable@v1.0.4.

Callers 1

InitMethod · 0.85

Calls 8

WorkDirectoryMethod · 0.80
ContextMethod · 0.65
DialContextMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
InfoMethod · 0.45
ErrorMethod · 0.45
ReadAllMethod · 0.45

Tested by

no test coverage detected