Skip to content

fix: close temp file handle before removal #3672

Merged
mdelapenya merged 3 commits intotestcontainers:mainfrom
acouvreur:fix/dind-load-image-windows-file-lock
May 7, 2026
Merged

fix: close temp file handle before removal #3672
mdelapenya merged 3 commits intotestcontainers:mainfrom
acouvreur:fix/dind-load-image-windows-file-lock

Conversation

@acouvreur
Copy link
Copy Markdown
Contributor

What does this PR do?

When using LoadFile on dind or k3s, the temporary file descriptor is not closed.

On some OS (such as windows), this fails upon deletion of the temp file.

Why is it important?

Related issues

acouvreur added 2 commits May 7, 2026 08:42
On some OS (such as Windows), keeping a file descriptor open prevents you from deleting the file.
On some OS (such as Windows), keeping a file descriptor open prevents you from deleting the file.
@acouvreur acouvreur requested a review from a team as a code owner May 7, 2026 12:45
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit f8e88af
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/69fc8985804c490008e3f390
😎 Deploy Preview https://deploy-preview-3672--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8de3e8de-d0e1-4f01-9e1b-cc22f1bc88c8

📥 Commits

Reviewing files that changed from the base of the PR and between 0c15e97 and f8e88af.

📒 Files selected for processing (2)
  • modules/dind/dind.go
  • modules/k3s/k3s.go

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced file handling in container image loading operations with explicit closure of temporary files and proper error checking to ensure reliable and consistent operation.

Walkthrough

Both the DinD and K3s container image loading modules add explicit closure of temporary image tar files immediately after creation. Each module now checks for close errors and returns a wrapped error before proceeding with file operations. Deferred cleanup remains unchanged.

Changes

Temporary File Resource Management

Layer / File(s) Summary
DinD File Closure
modules/dind/dind.go
LoadImage adds explicit close of the temporary images file right after creation, with error wrapping for close failures, before using the file path for SaveImages, CopyFileToContainer, and image load operations. Deferred cleanup unchanged.
K3s File Closure
modules/k3s/k3s.go
LoadImagesWithOpts follows the same pattern: closes the temporary file immediately after creation with dedicated error handling, then proceeds with SaveImagesWithOpts, CopyFileToContainer, and image import operations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A file to hold, then let it go,
Before its path begins to flow,
Close it quick, check if all's well,
Then use that path—a simple spell!
Two modules sync, no leaks remain,
Resources freed, the code's more sane. 🧡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: closing temporary file handles before removal to fix platform-specific deletion failures.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem (unclosed file descriptor on Windows) and the motivation for the fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mdelapenya mdelapenya self-assigned this May 7, 2026
@mdelapenya mdelapenya added the bug An issue with the library label May 7, 2026
Copy link
Copy Markdown
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM! I recently saw something similar for other project on Windows, so this makes sense, thanks!

@mdelapenya mdelapenya merged commit 244a915 into testcontainers:main May 7, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue with the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants