Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created August 21, 2011 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottwb/1161210 to your computer and use it in GitHub Desktop.
Save scottwb/1161210 to your computer and use it in GitHub Desktop.
Monkey-hack to retry SSL "Connection reset by peer" failures to Rackspace Cloud Files with CarrierWave
module CarrierWave
module Storage
class Fog
class File
alias :store_without_safety_net :store
def store(new_file)
retries_remaining = 3
begin
store_without_safety_net(new_file)
rescue Excon::Errors::SocketError => e
if e.inspect =~ /Connection reset by peer/
retries_remaining -= 1
if retries_remaining <= 0
raise
else
retry
end
else
raise
end
end
end
end
end
end
end
@charlietran
Copy link

thanks so much for this, saved me at crunch time as well! ever discover more about this issue?

@scottwb
Copy link
Author

scottwb commented Feb 13, 2012

You know, I never really dug into it. I've been running in production with this hack for a few months and it's totally out-of-sight-out-of-mind now. As far as I know, the problem still exists and the hack above is happily taking care of it for me.

Glad it's not just me seeing this. I thought maybe I was going crazy.

@scottwb
Copy link
Author

scottwb commented Feb 14, 2012

@charlietran I just added a new gist that contains the full version of this patch that I am now using in production. The only real difference since the original is that I added this protection to a couple additional methods. You can see the new gist here: https://gist.github.com/1822442

@geemus
Copy link

geemus commented Feb 14, 2012

Hey guys, sorry about the trouble you were having there. I just patched fog to do retries itself on put_object by adding :idempotent => true to the request for put_object, see:
fog/fog@a1fe973
After the next release (hopefully this week), your issue should hopefully be resolved and no longer require this monkey patch. There may be other things that should be marked as retry-able as well, so let me know (or send me a patch) if you run into any other ones. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment