{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/paperclip/issues/2065","repository_url":"https://api.github.com/repos/thoughtbot/paperclip","labels_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/2065/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/2065/comments","events_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/2065/events","html_url":"https://github.com/thoughtbot/paperclip/pull/2065","id":119575985,"number":2065,"title":"fix S3 adapter runtime constant definition not being thread-safe","user":{"login":"erkki","id":3516,"avatar_url":"https://avatars.githubusercontent.com/u/3516?v=3","gravatar_id":"","url":"https://api.github.com/users/erkki","html_url":"https://github.com/erkki","followers_url":"https://api.github.com/users/erkki/followers","following_url":"https://api.github.com/users/erkki/following{/other_user}","gists_url":"https://api.github.com/users/erkki/gists{/gist_id}","starred_url":"https://api.github.com/users/erkki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erkki/subscriptions","organizations_url":"https://api.github.com/users/erkki/orgs","repos_url":"https://api.github.com/users/erkki/repos","events_url":"https://api.github.com/users/erkki/events{/privacy}","received_events_url":"https://api.github.com/users/erkki/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-30T20:37:42Z","updated_at":"2016-03-24T05:15:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/thoughtbot/paperclip/pulls/2065","html_url":"https://github.com/thoughtbot/paperclip/pull/2065","diff_url":"https://github.com/thoughtbot/paperclip/pull/2065.diff","patch_url":"https://github.com/thoughtbot/paperclip/pull/2065.patch"},"body":"After debugging seemingly random exceptions on DEFAULT_PERMISSION not being defined in a threaded downloader, it became clear the S3 adapter is not thread safe.\r\n\r\nHere is a sample run with 2 threads and debug prints:\r\n```\r\n#<Thread:0x007f925d34eeb8> before defined? check AWS_CLASS\r\n#<Thread:0x007f925d34eeb8> before const_set AWS_CLASS\r\n#<Thread:0x007f925d34eeb8> after const_set AWS_CLASS\r\n#<Thread:0x007f925d34ed78> before defined? check AWS_CLASS\r\n#<Thread:0x007f925d34ed78> before usage of const DEFAULT_PERMISSION\r\n#<Thread:0x007f925d34eeb8> before const_set DEFAULT_PERMISSION\r\n#<Thread:0x007f925d34eeb8> after const_set DEFAULT_PERMISSION\r\n#<Thread:0x007f925d34eeb8> before usage of const DEFAULT_PERMISSION\r\n#<Thread:0x007f925d34eeb8> after usage of const DEFAULT_PERMISSION\r\n```\r\nThe added Thread#exclusive block is probably too wide and blunt of an fix but should be fine until a better one comes along.\r\n\r\nDecided to use 10 threads in the spec after making sure of a good-enough failure rate (it is still possible to get false-positives but they should be rare)."},"comment":{"url":"https://api.github.com/repos/thoughtbot/paperclip/issues/comments/200671002","html_url":"https://github.com/thoughtbot/paperclip/pull/2065#issuecomment-200671002","issue_url":"https://api.github.com/repos/thoughtbot/paperclip/issues/2065","id":200671002,"user":{"login":"erkki","id":3516,"avatar_url":"https://avatars.githubusercontent.com/u/3516?v=3","gravatar_id":"","url":"https://api.github.com/users/erkki","html_url":"https://github.com/erkki","followers_url":"https://api.github.com/users/erkki/followers","following_url":"https://api.github.com/users/erkki/following{/other_user}","gists_url":"https://api.github.com/users/erkki/gists{/gist_id}","starred_url":"https://api.github.com/users/erkki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erkki/subscriptions","organizations_url":"https://api.github.com/users/erkki/orgs","repos_url":"https://api.github.com/users/erkki/repos","events_url":"https://api.github.com/users/erkki/events{/privacy}","received_events_url":"https://api.github.com/users/erkki/received_events","type":"User","site_admin":false},"created_at":"2016-03-24T05:15:42Z","updated_at":"2016-03-24T05:15:42Z","body":"Sure thing, let me check asap and get back to you, thanks!"}}