{"action":"closed","issue":{"url":"https://api.github.com/repos/shrinerb/shrine/issues/338","repository_url":"https://api.github.com/repos/shrinerb/shrine","labels_url":"https://api.github.com/repos/shrinerb/shrine/issues/338/labels{/name}","comments_url":"https://api.github.com/repos/shrinerb/shrine/issues/338/comments","events_url":"https://api.github.com/repos/shrinerb/shrine/issues/338/events","html_url":"https://github.com/shrinerb/shrine/issues/338","id":392795229,"node_id":"MDU6SXNzdWUzOTI3OTUyMjk=","number":338,"title":"Temp files deleted before upload","user":{"login":"mcelicalderon","id":3926414,"node_id":"MDQ6VXNlcjM5MjY0MTQ=","avatar_url":"https://avatars3.githubusercontent.com/u/3926414?v=4","gravatar_id":"","url":"https://api.github.com/users/mcelicalderon","html_url":"https://github.com/mcelicalderon","followers_url":"https://api.github.com/users/mcelicalderon/followers","following_url":"https://api.github.com/users/mcelicalderon/following{/other_user}","gists_url":"https://api.github.com/users/mcelicalderon/gists{/gist_id}","starred_url":"https://api.github.com/users/mcelicalderon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcelicalderon/subscriptions","organizations_url":"https://api.github.com/users/mcelicalderon/orgs","repos_url":"https://api.github.com/users/mcelicalderon/repos","events_url":"https://api.github.com/users/mcelicalderon/events{/privacy}","received_events_url":"https://api.github.com/users/mcelicalderon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-12-19T22:04:23Z","updated_at":"2018-12-22T22:53:50Z","closed_at":"2018-12-22T22:53:50Z","author_association":"NONE","body":"### Brief Description\r\nWhen doing some custom processing to add versions in an uploaded file, I get a file not found error if one of the versions takes too long to upload\r\n\r\n### Expected behavior\r\nShould be able to upload as many versions as necessary without some of the temfile versions being deleted before they are uploaded\r\n\r\n### Actual behavior\r\nIf the first version that is uploaded takes a bit longer than usual (more than 1 sec) the remaining versions will fail to upload as they have been removed from the temp file directory.\r\n\r\n### Shrine config file\r\n```ruby\r\nrequire 'shrine/storage/file_system'\r\nrequire 'shrine/storage/s3'\r\n\r\nShrine.storages = if Rails.env.test?\r\n  {\r\n    cache: Shrine::Storage::FileSystem.new('tmp', prefix: 'uploads/cache'),\r\n    store: Shrine::Storage::FileSystem.new('tmp', prefix: 'uploads')\r\n  }\r\nelse\r\n  aws_secrets = Rails.application.secrets.aws\r\n\r\n  {\r\n    cache: Shrine::Storage::FileSystem.new('tmp', prefix: 'uploads/cache'),\r\n    store: Shrine::Storage::S3.new(\r\n      prefix:            Rails.env,\r\n      bucket:            aws_secrets[:bucket],\r\n      access_key_id:     aws_secrets[:access_key_id],\r\n      secret_access_key: aws_secrets[:secret_access_key],\r\n      region:            aws_secrets[:region]\r\n    )\r\n  }\r\nend\r\n\r\nShrine.plugin :activerecord\r\nShrine.plugin :delete_promoted\r\nShrine.plugin :remove_invalid\r\nShrine.plugin :determine_mime_type\r\nShrine.plugin :infer_extension\r\nShrine.plugin :processing\r\nShrine.plugin :versions\r\nShrine.plugin :copy\r\nShrine.plugin :remote_url, max_size: 50 * 1024 * 1024\r\nShrine.plugin :validation_helpers, default_messages: {\r\n  max_size:            ->(max) { I18n.t('errors.file.max_size', max_size: max) },\r\n  mime_type_inclusion: ->(whitelist) { I18n.t('errors.file.mime_type_inclusion', whitelist: whitelist) }\r\n}\r\n```\r\n\r\n### Simplest self-contained example code to demonstrate issue\r\n```ruby\r\nprocess(:store) do |io, _context|\r\n    io.download do |download|\r\n        pipeline = ImageProcessing::MiniMagick.source(download).convert('jpg')\r\n\r\n        thumbnail = pipeline.resize_to_limit!(1000, 1000)\r\n\r\n        { original: io, thumbnail: thumbnail }\r\n    end\r\nend\r\n```\r\n\r\n### Backtrace\r\n```\r\nNo such file or directory @ rb_file_s_size - /tmp/20181219-1-1r3p9az20181219-1-jef5uh\r\n----------\r\n/GEM_ROOT/gems/aws-sdk-s3-1.30.0/lib/aws-sdk-s3/file_uploader.rb:31→ size\r\n--\r\n/GEM_ROOT/gems/aws-sdk-s3-1.30.0/lib/aws-sdk-s3/file_uploader.rb:31→ upload\r\n/GEM_ROOT/gems/aws-sdk-s3-1.30.0/lib/aws-sdk-s3/customizations/object.rb:308→ upload_file\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/storage/s3.rb:478→ put\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/storage/s3.rb:301→ upload\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:348→ copy\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:337→ put\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:321→ _store\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/versions.rb:233→ _store\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/versions.rb:228→ block in _store\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/versions.rb:227→ each\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/versions.rb:227→ inject\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/versions.rb:227→ _store\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:248→ store\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:226→ upload\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:658→ store!\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:588→ promote\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/delete_promoted.rb:14→ promote\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:582→ _promote\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine.rb:577→ finalize\r\n/GEM_ROOT/gems/shrine-2.13.0/lib/shrine/plugins/activerecord.rb:113→ block in included\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426→ instance_exec\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:426→ block in make_lambda\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:261→ block in conditional\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:517→ block in invoke_after\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:517→ each\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:517→ invoke_after\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:133→ run_callbacks\r\n/GEM_ROOT/gems/airbrake-7.4.0/lib/airbrake/rails/active_record.rb:25→ run_callbacks\r\n/GEM_ROOT/gems/activesupport-5.2.2/lib/active_support/callbacks.rb:816→ _run_commit_callbacks\r\n/GEM_ROOT/gems/activerecord-5.2.2/lib/active_record/transactions.rb:346→ committed!\r\n```\r\n\r\n### System configuration\r\n**Ruby version**: 2.5.3\r\n\r\n**Shrine version**: 2.13.0\r\n\r\n### Notes\r\nFollowing the stack trace, looks like the code might be loosing the reference to the tempfile as only the path (string) is used on the upload. If no reference is kept from the tempfile might be the reason why it gets deleted. Changing the code to upload the smaller file first `{ thumbnail: thumbnail, original: io }` fixes it every time. But probably would still fail if uploading more versions.\r\n\r\nLet me know if I can provide additional information on this.\r\nThanks\r\n"}}
{"actor":{"display_login":"mcelicalderon"}}