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

Atomic file partial filename should be random (or use locking somehow) #11

Open
joonas-fi opened this issue Jan 30, 2022 · 1 comment
Open
Labels
bug Something isn't working

Comments

@joonas-fi
Copy link
Member

If two processes are racing to make the same final file:

rename /run/notifydedup/counter.json.part /run/notifydedup/counter.json: no such file or directory; also failed removing temp file: remove /run/notifydedup/counter.json.part: no such file or directory

Think timeline:

  • Process 1 starts producing counter.json.part
  • Process 2 starts producing counter.json.part, overriding first one
  • Process 1 renames the part file to target (thinking it is its own part file), effectively replacing the target file with an incomplete file

Is it possible to use locking with the part file in a way that two competing processes are not racing to produce the target file?

@joonas-fi joonas-fi added the bug Something isn't working label Jan 30, 2022
joonas-fi added a commit that referenced this issue Jan 30, 2022
@joonas-fi
Copy link
Member Author

joonas-fi commented Jan 30, 2022

The above fix mitigates this, but leaving open to consider:

  • Testing of this fix
  • Should we use file locking on the partial file, so if a dangling file was left by a crashed process, we know that if we get a lock we know we can "regain ownership" of the partial file. NOTE: make sure file is truncated, so we don't build on top of garbage
    • Currently a dangling file prevents atomic file write from working at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant