Skip to content

fix: retain Tempfile reference to prevent cloud-init ISO GC race#191

Merged
ekohl merged 2 commits into
fog:masterfrom
ajmeese7:fix/cloud-init-iso-tempfile-gc
May 30, 2026
Merged

fix: retain Tempfile reference to prevent cloud-init ISO GC race#191
ekohl merged 2 commits into
fog:masterfrom
ajmeese7:fix/cloud-init-iso-tempfile-gc

Conversation

@ajmeese7
Copy link
Copy Markdown
Contributor

@ajmeese7 ajmeese7 commented May 30, 2026

Summary

Splits an unrelated fix out of #190 at a maintainer's request.

generate_config_iso called Tempfile.new(['init', '.iso']).path and immediately discarded the Tempfile object. Once GC finalized it, the underlying ISO file was unlinked before downstream code could read it, causing flaky ENOENT failures.

This retains the Tempfile reference for the lifetime of the block and explicitly cleans it up in an ensure.

Changes

  • Keep the Tempfile object in iso_tempfile; derive isofile from .path.
  • Add ensure iso_tempfile&.close! to unlink deterministically instead of relying on GC timing.

Test plan

  • CI green (rubocop + test matrix 2.7–head)
  • cloud-init ISO generation no longer flakes on ENOENT

ajmeese7 and others added 2 commits May 30, 2026 09:27
The Tempfile object was immediately discarded after calling .path,
making it eligible for garbage collection. When GC finalized the
object, the underlying ISO file was deleted before File.size could
read it, causing flaky ENOENT failures in CI.
Copy link
Copy Markdown
Contributor

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation. I would have never suspected the GC to be so aggressive in cleaning it up. I suspected it was more due to leaking file descriptors.

@ekohl ekohl added the bug label May 30, 2026
@ekohl ekohl merged commit a7998aa into fog:master May 30, 2026
7 of 8 checks passed
@ajmeese7 ajmeese7 deleted the fix/cloud-init-iso-tempfile-gc branch May 30, 2026 14:33
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.

2 participants