Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

download! method doesn't close file

Open
#518 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby
Domain
devops

Research direction

Start at the download! implementation and trace how the Tempfile is handled. Reproduce the sequential download/read example from the issue, then add or update coverage for reading immediately after download; done means the read consistently sees complete contents without the caller closing the file.

Written by the indexing model from the issue text.

Description

which causes hard-to-debug errors when you download many files in a row and try to read the file contents immediately after downloading. It works most of the time, but at some point a downloaded file will not be flushed to disk completely when you try to read the file.

Reading only the partially written file from disk will, of course, result in corrupted file contents. I was able to avoid this behavior by explicitly closing the downloaded file before reading it again. But this was not very intuitive, so please consider closing the file within the download method.

tmp_file = Tempfile.new(file_name, tmp_dir)
src = File.join(dir, file_name)
          
download! src, tmp_file, log_percent: -1

# it's important to close the tmp file, otherwise data might not be written 
# to disk already, when we try to read the file again
tmp_file.close 

begin
   File.read tmp_file
ensure
   tmp_file.close
   tmp_file.unlink
end

Dominant language
Ruby
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from capistrano/sshkit

All issues in capistrano/sshkit

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.