Skip to content

global variable 'cpuOut' is always nil #61

@RemoteOnly

Description

@RemoteOnly
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions