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

Use io.Discard instead of /dev/null for discarding output #354

Merged
merged 8 commits into from
Aug 31, 2022

Conversation

anuraaga
Copy link
Contributor

Writing to /dev/null is still a system call which adds quite a bit of overhead even though we don't want to actually do anything. io.Discard drops within Go code itself for much better efficiency, and a step towards Windows compatibility.

Thank you for contributing to Coraza WAF, your effort is greatly appreciated
Before submitting check if what you want to add to coraza list meets quality standards before sending pull request. Thanks!

Note: that go.mod and go.sum can only be modified for tested dependency updates or justified new features.

Make sure that you've checked the boxes below before you submit PR:

Thanks for your PR ❤️

waf.go Show resolved Hide resolved
} else {
file = io.Discard
// Nothing to close so just set a no-op
sl.file = io.NopCloser(&bytes.Buffer{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still don't have a mechanism to close WAF instances. It should handle closing log writters and audit writters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm this is something to fix in another PR? Here we're just keeping the existing code working, i.e., to support the Close method on line 58

loggers/serial_writer.go Outdated Show resolved Hide resolved
loggers/serial_writer.go Outdated Show resolved Hide resolved
Copy link
Member

@jcchavezs jcchavezs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@anuraaga
Copy link
Contributor Author

Hi all, this has been open for a while can it be merged?

@jptosso jptosso merged commit 042887f into corazawaf:v3/dev Aug 31, 2022
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