Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add http/pprof server over unix socket for debug (#295)#296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intorelease/1.0fromspike/cherry-pick-pprof-1.0
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
1 change: 1 addition & 0 deletionsmain.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ import (
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs

func main() {
servePprof()
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: provider.New,
})
Expand Down
42 changes: 42 additions & 0 deletionspprof_unix.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
//go:build !windows

package main

import (
"net"
"net/http"
"net/http/pprof"
"os"
)

// servePprof starts an HTTP server running the pprof goroutine handler on a local unix domain socket. As described in
// https://github.com/coder/coder/issues/14726 it appears this process is sometimes hanging, unable to exit cleanly,
// and this prevents additional Coder builds that try to reinstall this provider. A goroutine dump should allow us to
// determine what is hanging.
//
// This function is best-effort, and just returns early if we fail to set up the directory/listener. We don't want to
// block the normal functioning of the provider.
func servePprof() {
// Coder runs terraform in a per-build subdirectory of the work directory. The per-build subdirectory uses a
// generated name and is deleted at the end of a build, so we want to place our unix socket up one directory level
// in the provisionerd work directory, so we can connect to it from provisionerd.
err := os.Mkdir("../.coder", 0o700)
if err != nil && !os.IsExist(err) {
return
}

// remove the old file, if it exists. It's probably from the last run of the provider
if err = os.Remove("../.coder/pprof"); err != nil && !os.IsNotExist(err) {
return
}
l, err := net.Listen("unix", "../.coder/pprof")
if err != nil {
return
}
mux := http.NewServeMux()
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
srv := http.Server{Handler: mux}
go srv.Serve(l)
// We just leave the server and domain socket up forever. Go programs exit when the `main()` function returns, so
// this won't block exiting, and it ensures the pprof server stays up for the entire lifetime of the provider.
}
6 changes: 6 additions & 0 deletionspprof_windows.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
//go:build windows

package main

// servePprof is not supported on Windows
func servePprof() {}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp