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

Changes to sidecar to fix some issues #30

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

allenmqcymp
Copy link
Contributor

While working on reloading rule files, I noticed two errors.

  1. Open file does not open with the correct permissions if the file already exists
  2. Truncate file does not update the file pointer, leading to some weird control characters

The PR fixes both the issues

@roidelapluie
Copy link

I dont think the way we deal with file is safe, we should create a new one then rename it to the old one. This way this is atomic.

@squat
Copy link

squat commented Nov 17, 2020

Great suggestion, @roidelapluie. The current implementation in master is simply broken whenever you write the second time, even ignoring race conditions, so what @allenmqcymp is proposing is a net-improvement IMO. In any case, @allenmqcymp, if you are up for it, implementing the solution @roidelapluie suggests would be even better :)

@allenmqcymp
Copy link
Contributor Author

@roidelapluie @squat latest commit does just that. PTAL :)

cmd/mixtool/server.go Outdated Show resolved Hide resolved
cmd/mixtool/server.go Outdated Show resolved Hide resolved
cmd/mixtool/server.go Outdated Show resolved Hide resolved
cmd/mixtool/server.go Outdated Show resolved Hide resolved
if err != nil {
return false, fmt.Errorf("create rule file: %w", err)
}
fileData, err := ioutil.ReadFile(p.ruleFile)
Copy link

Choose a reason for hiding this comment

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

Rather than reading both rule files completely into memory, i think it could be better to:

  1. Write the new rules to a temp file
  2. Get a file pointer to the old file
  3. Compare the readers for both files using the existing helper fun
  4. If equal, return early
  5. If not equal, rename the temp file

@metalmatze
Copy link
Collaborator

Looks good, only needs a rebase to get rid of the conflict in go.sum 🙂

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.

4 participants