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

gomplate.RunTemplates leaks file handles #995

Closed
rdriesner opened this issue Dec 8, 2020 · 2 comments · Fixed by #1199
Closed

gomplate.RunTemplates leaks file handles #995

rdriesner opened this issue Dec 8, 2020 · 2 comments · Fixed by #1199
Labels

Comments

@rdriesner
Copy link

I´m running gomplate via RunTemplates twice in my code and have identified on windows that f.e. Rename or Delete of used files in the datasource or context are not accessible. I know that gomplate is designed to run as cli.
The problem can be fixed if the opened files are closed which are read at:

  • datasource_file.go -> readFile()
  • file.go -> Write()
  • readers.go -> Read()

Closing the files at this methods solved the leaking, maybe there is a better way.
BR
Robert

@hairyhenderson
Copy link
Owner

Hi @rdriesner, thanks for logging this!

I know that gomplate is designed to run as cli.

While true, I would like gomplate to be usable as a library as well - there's some history in #548 about that if you're interested!

I'll take a look at this soon.

@hairyhenderson
Copy link
Owner

Finally getting around to this 😅

  • readers.go -> Read()

This is the LazyReadCloser, so it can't be closed in the Read function - it must only be closed by the Close function (it's a io.ReadCloser). Ultimately, files opened lazily with this get closed once template execution is complete (here).

The others can be easily closed!

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

Successfully merging a pull request may close this issue.

2 participants