title: ActiveStorage image blob disappears
body: <p>In Rails 5.2.1, I have ActiveStorage (5.2.1) configured for the <code>Disk</code> service.</p>
  
  <p>I have a Pic model:</p>
  
  <pre><code>class Pic &lt; ApplicationRecord
    has_one_attached :image
  end
  </code></pre>
  
  <p>I can attach images:</p>
  
  <pre><code>imgpath = "/tmp/images/..."
  Pic.first.image.attach(io: File.open(imgpath), filename: imgpath)
  </code></pre>
  
  <p>I wanted to do this in something like a Rake task (but the result is the same if done from the Rails console) to batch-upload images, like for example:</p>
  
  <pre><code>pfs = Dir['testpics/*']
  Pic.all.each { |pic|
    pf = pfs.shift
    pic.image.attach(io: File.open(pf), filename: pf)
  }
  </code></pre>
  
  <p>This runs without errors. However, quiet surprisingly (to me at least) <em>some</em> images don't have a corresponding blob afterwards, and queries fail with 500 Internal Server Error: <code>Errno::ENOENT (No such file or directory @ rb_sysopen</code>.</p>
  
  <p>Checking <code>pic.image.attached?</code> returns true. However, <code>pic.image.download</code> throws an exception.</p>
  
  <p>Even stranger, calling <code>pic.image.download</code> right after attaching it <em>does</em> work. 2 seconds later it doesn't.</p>
  
  <p>The only way I could come up with to tell if an image uploaded correctly is to wait ~2 seconds after attaching it, and <em>then</em> try to download. If I keep retrying the attach after waiting 2 seconds and checking if it's ok, all images will be ok. But obviously this is not the right thing to do. :) Simply waiting between attach calls does not help, I have to check after the wait, then reattach and then check again until it is ok - sometimes ok on the first try, sometimes 10th, but <em>eventually</em> it will succeed.</p>
  
  <p>This is all on my local disk, not for example ephemeral storage in Heroku. Also I'm running it on Ubuntu 18.04 (Bionic), with nothing installed that should remove blobs (ie. no antivirus or similar). I really think the problem is internal to ActiveStorage, or the way I use it maybe.</p>
  
  <p>What's going on? Where do blobs go after a few seconds, when they were already uploaded succesfully?</p>
  
  <p>With the S3 service everything is fine, blobs don't disappear.</p>