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

file fd leak #1459

Closed
fengjun2016 opened this issue Dec 26, 2024 · 0 comments
Closed

file fd leak #1459

fengjun2016 opened this issue Dec 26, 2024 · 0 comments

Comments

@fengjun2016
Copy link
Contributor

fengjun2016 commented Dec 26, 2024

Observed

1.open file fd but not close in time
截屏2024-12-26 10 55 30

Expected behaviour

no file fd leak

Code example

file location: internal/cmd/release/main.go

func gitHubOutputReleaseURLIfAvailable(url string) {
	if len(url) == 0 {
		return
	}

	gitHubOutputFile, exists := os.LookupEnv("GITHUB_OUTPUT")
	if !exists {
		return
	}

	f, err := os.OpenFile(gitHubOutputFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
	if err != nil {
		log.Fatalln(err)
		return
	}
        
        // return but not close f fd, then fd leak
	if _, err := f.WriteString(fmt.Sprintf("RELEASE_URL=%s\n", url)); err != nil {
		log.Fatalln(err)
		return
	}

	if err := f.Close(); err != nil {
		log.Fatalln(err)
		return
	}
}

Tasks

Preview Give feedback
No tasks being tracked yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants