Skip to content

Attempt to fix race conditions with non-atomic file copy for worker jars #90

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

Closed
wants to merge 2 commits into from

Conversation

jjudd
Copy link

@jjudd jjudd commented Apr 8, 2025

We were copying a file used by multiple threads directly to its destination. Problem is that copying is not an atomic action, so we could end up in states where the file wasn't correct when it was used.

This should avoid that issue by first copying the file to a temp file and then using an atomic move to move the file to the destination used by other threads.

@jjudd jjudd requested a review from jadenPete April 8, 2025 17:31
jjudd added 2 commits April 8, 2025 11:52
We were copying a file used by multiple threads directly to its
destination. Problem is that copying is not an atomic action, so we
could end up in states where the file wasn't correct when it was used.

This should avoid that issue by first copying the file to a temp file
and then using an atomic move to move the file to the destination used
by other threads.
@jjudd jjudd force-pushed the jjudd-atomic-move branch from d936588 to 24d2bc2 Compare April 8, 2025 17:52
Files.createDirectories(workerJar.getParent())
Files.copy(workRequestJar, workerJar)
Files.move(tmpWorkerJar.get, workerJar, StandardCopyOption.ATOMIC_MOVE)
Copy link

@jnowjack-lucidchart jnowjack-lucidchart Apr 8, 2025

Choose a reason for hiding this comment

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

ATOMIC_MOVE: ... If the target file exists then it is implementation specific if the existing file is replaced or this method fails by throwing an IOException (documentation)

Do you know what happens on our systems? Does it replace or throw an error?

Copy link
Author

Choose a reason for hiding this comment

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

I do not know. REPLACE_EXISTING is not set, so I'm hoping it would throw an error.

Choose a reason for hiding this comment

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

That documentation also states for ATOMIC_MOVE:

The move is performed as an atomic file system operation and all other options are ignored.

so I don't think it matters if REPLACE_EXISTING is set or not, it may or may not throw an error.

@jjudd
Copy link
Author

jjudd commented Apr 18, 2025

Closing in favor of #91

@jjudd jjudd closed this Apr 18, 2025
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.

None yet

3 participants