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

fix: broken unclosed files on windows #1139

Open
wants to merge 4 commits into
base: gh-windows
Choose a base branch
from

Conversation

jabdr
Copy link
Contributor

@jabdr jabdr commented Aug 24, 2024

This patch fixes tests and log file behaviour on windows. The big problem here is, that windows does not allow to delete files with open file descriptors.

To solve this problem I had to implement the following changes:

  • close temp files created during the tests
  • close opened log files
  • Add io.Closer to the WAF interface to allow closing log files

This was originally intended as a small fix, but now it requires an API change. Technically, it is not required to Close the log files on linux, but I think it is still a good best practice to not rely on GC alone.

I removed the os.Remove calls from testing/auditlog_test.go and replaced them with Close, as go test already cleans them up, but only if they are properly closed (on windows).

@jabdr jabdr marked this pull request as ready for review August 24, 2024 17:15
@jabdr jabdr requested a review from a team as a code owner August 24, 2024 17:15
@jptosso
Copy link
Member

jptosso commented Aug 24, 2024

Unfortunately this is a breaking change. We cannot update the public waf interface.
But this is a v4 TODO

@jabdr
Copy link
Contributor Author

jabdr commented Aug 24, 2024

I thought so already. Please let me know if I can do anything to help getting this merged to v4.

@jcchavezs
Copy link
Member

jcchavezs commented Aug 25, 2024 via email

@jcchavezs
Copy link
Member

jcchavezs commented Aug 25, 2024 via email

@jabdr
Copy link
Contributor Author

jabdr commented Aug 25, 2024

@jcchavezs

This looks good to me. Just remove the closer from the interface and keep the others.

I can do that. Should I create a seperate PR for v4 that includes the close on the public interface?

Actually giving a second thought we should only close those closeables we open so let's carefully review the cases.

Do you mean the debuglog Close? Let me think about it.

@jabdr
Copy link
Contributor Author

jabdr commented Aug 25, 2024

@jcchavezs @jptosso

I removed the changes to debuglog itself. You are correct, it should not close the debug file handle, as it only receives the io.Writer from WAF. Instead I choose to add a field to the internal WAF struct. So the file creator/opener is also closing the file in the end.

I removed the public WAF interface change from this PR, but I recommend to add it to the next major version.

@jcchavezs jcchavezs changed the base branch from main to gh-windows October 2, 2024 19:19
@jcchavezs
Copy link
Member

Please rebase your PR on top of gh-windows

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

Successfully merging this pull request may close these issues.

3 participants