Skip to content
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

global variable 'cpuOut' is always nil #61

Open
RemoteOnly opened this issue Jun 8, 2022 · 0 comments
Open

global variable 'cpuOut' is always nil #61

RemoteOnly opened this issue Jun 8, 2022 · 0 comments

Comments

@RemoteOnly
Copy link

package service

...
var cpuOut *os.File
...

// BeforeRun takes care of necessary actions such as creating files
// before the beat should run.
func BeforeRun() {
	logger := logp.NewLogger("service")
	if withCPUProfile() {
		cpuOut, err := os.Create(*cpuprofile)
		....
	}

	...
}

cpuOut, err := os.Create(*cpuprofile) will create a new variable cpuOut, which is different with global variable var cpuOut *os.File. Global variable var cpuOut *os.File is never set and one error will be created when function Cleanup() is called.

func Cleanup() {
	logger := logp.NewLogger("service")
	if withCPUProfile() {
		pprof.StopCPUProfile()
		cpuOut.Close() // -------- cpuOut is nil
	}

        ...
}

Besides, the cpuprofile will not be closed in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant