Skip to content

Commit c5698e3

Browse files
cuishuangcherrymui
authored andcommitted
cmd/pprof: fix exception when file or path contains colon
Fixes #63924 Change-Id: I4ea17979faaca04eb6b046abffca2dd77397e0cb Reviewed-on: https://go-review.googlesource.com/c/go/+/539595 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: David Chase <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: shuang cui <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 959e65c commit c5698e3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/cmd/pprof/pprof.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ type fetcher struct {
4545
}
4646

4747
func (f *fetcher) Fetch(src string, duration, timeout time.Duration) (*profile.Profile, string, error) {
48+
// Firstly, determine if the src is an existing file on the disk.
49+
// If it is a file, let regular pprof open it.
50+
// If it is not a file, when the src contains `:`
51+
// (e.g. mem_2023-11-02_03:55:24 or abc:123/mem_2023-11-02_03:55:24),
52+
// url.Parse will recognize it as a link and ultimately report an error,
53+
// similar to `abc:123/mem_2023-11-02_03:55:24:
54+
// Get "http://abc:123/mem_2023-11-02_03:55:24": dial tcp: lookup abc: no such host`
55+
if _, openErr := os.Stat(src); openErr == nil {
56+
return nil, "", nil
57+
}
4858
sourceURL, timeout := adjustURL(src, duration, timeout)
4959
if sourceURL == "" {
5060
// Could not recognize URL, let regular pprof attempt to fetch the profile (eg. from a file)

0 commit comments

Comments
 (0)