Skip to content

fix: close temp downloads before removing them on error - #340

Merged
runkids merged 1 commit into
mainfrom
fix/close-temp-before-remove
Oct 2, 2026
Merged

runkids merged 1 commit into
mainfrom
fix/close-temp-before-remove

Conversation

@runkids

@runkids runkids commented Oct 2, 2026

Copy link
Copy Markdown
Owner

What

Follow-up to the review note on #335. downloadArchive (cmd/skillshare/upgrade.go) and downloadToTemp (internal/uidist/uidist.go) called os.Remove(tmp.Name()) in their error branches while the temp file was still open — the defer tmp.Close() had not fired yet. On Windows, deleting an open file fails, so an interrupted or oversized download could leave up to ~100 MB in %TEMP%.

Both error branches now close the file before removing it. The success path is unchanged.

Tests

TestDownloadArchive_InterruptedDownloadLeavesNoTempFile aborts the response mid-body and asserts the temp dir is empty afterwards. Note: Linux allows unlinking an open file, so this test also passes on Linux without the fix. It pins the behavior and only catches the original bug when run on Windows.

gofmt -l cmd internal                               (no output)
go vet ./cmd/skillshare ./internal/uidist           ok (linux + GOOS=windows)
make check (devcontainer)                           ok

Not run on a real Windows machine.

Both release downloaders removed the temp file while it was still open,
relying on the deferred Close. Windows refuses to delete an open file, so
an interrupted or oversized download could leave up to ~100 MB behind in
%TEMP%. Closing first makes the cleanup work on every platform.

Raised in review of #335; downloadToTemp in uidist had the same pattern.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T14:39:51.021834Z e4f4194 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@runkids
runkids merged commit dadbbc7 into main Oct 2, 2026
7 checks passed
@runkids
runkids deleted the fix/close-temp-before-remove branch October 2, 2026 14:46
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.

1 participant