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 race condition by memoizing Tempfile objects #461

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

alexjfisher
Copy link
Contributor

Previously, the certificate and private_key methods created Tempfile objects without maintaining references after the methods exited. This allowed the Ruby garbage collector to collect and delete these temporary files at any time. As a result, there was a race condition where the keytool binary could fail with a java.io.FileNotFoundException if the temporary files were deleted before keytool accessed them.

This commit resolves the issue by memoizing the Tempfile objects using instance variables (@temp_certificate_file and @temp_private_key_file). By caching these objects, we prevent them from being garbage collected prematurely, ensuring that the temporary files remain available for the duration of the provider instance.

Fixes #425

Previously, the `certificate` and `private_key` methods created `Tempfile`
objects without maintaining references after the methods exited. This allowed
the Ruby garbage collector to collect and delete these temporary files at any
time. As a result, there was a race condition where the `keytool` binary could
fail with a `java.io.FileNotFoundException` if the temporary files were deleted
before `keytool` accessed them.

This commit resolves the issue by memoizing the `Tempfile` objects using
instance variables (`@temp_certificate_file` and `@temp_private_key_file`). By
caching these objects, we prevent them from being garbage collected
prematurely, ensuring that the temporary files remain available for the
duration of the provider instance.

Fixes puppetlabs#425
@alexjfisher alexjfisher requested a review from a team as a code owner October 23, 2024 10:10
@amitkarsale amitkarsale merged commit a9b22d0 into puppetlabs:main Feb 5, 2025
46 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

random failures in java_ks provider
3 participants