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)
| 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. |
| 464 | func 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. |
no test coverage detected