-
Notifications
You must be signed in to change notification settings - Fork 22
chore: add http/pprof server over unix socket for debug #295
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//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.Stat("../.coder/pprof"); err == nil { | ||
if err = os.Remove("../.coder/pprof"); err != nil { | ||
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. | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build windows | ||
|
||
package main | ||
|
||
// servePprof is not supported on Windows | ||
func servePprof() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.