fix(execd): auto-recreate temp dir in stdLogDescriptor and combinedOutputDescriptor#415
Merged
Pangjiping merged 1 commit intoalibaba:mainfrom Mar 11, 2026
Conversation
…tputDescriptor When the /tmp directory is deleted inside a sandbox container, subsequent command execution fails with 'failed to get stdlog descriptor' because os.OpenFile with O_CREATE only creates the file, not the parent directory. Add os.MkdirAll(os.TempDir(), 0755) before file creation in both stdLogDescriptor and combinedOutputDescriptor so the temp directory is automatically recreated if it has been removed. Also fix a file descriptor leak in stdLogDescriptor where the stdout file was not closed when the stderr open failed. Fixes alibaba#400 Co-Authored-By: Claude <noreply@anthropic.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Pull request overview
Fixes execd command execution failures when the temp directory (e.g. /tmp) is deleted in sandbox containers by ensuring the temp directory is recreated before opening per-command log files.
Changes:
- Ensure
stdLogDescriptorandcombinedOutputDescriptorcallos.MkdirAll(os.TempDir(), ...)before opening output files. - Fix a
stdLogDescriptorfile descriptor leak by closingstdoutif openingstderrfails. - Add regression tests intended to validate auto-creation of the temp directory when
TMPDIRpoints to a missing path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| components/execd/pkg/runtime/command_common.go | Recreates temp dir before creating log/output files; closes stdout on stderr open failure. |
| components/execd/pkg/runtime/command_test.go | Adds regression tests for temp-dir auto-creation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Collaborator
|
It looks like an ignorable linter issue, I'll try to address these minor things all at once before the release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #400
When the
/tmpdirectory is deleted inside a sandbox container, all subsequent command execution fails withfailed to get stdlog descriptororfailed to get combined output descriptor. The root cause is thatos.OpenFilewithos.O_CREATEonly creates the file, not the parent directory — so once/tmpis gone, every command fails until the container is restarted.Changes
stdLogDescriptor: addos.MkdirAll(os.TempDir(), 0o755)before opening log files — auto-recreates/tmp(or whatever$TMPDIRpoints to) if it was removedcombinedOutputDescriptor: same fixstdLogDescriptorfd leak: closestdoutwhenstderropen fails (previously leaked the stdout*os.File)TestStdLogDescriptor_AutoCreatesTempDir,TestCombinedOutputDescriptor_AutoCreatesTempDir) that pointTMPDIRat a non-existent path and assert the directory is created on the first commandThe change is minimal and backward-compatible —
MkdirAllon an existing directory is a no-op, so there is no overhead in the normal case.🤖 Generated with Claude Code